package com.zhongwang.business.module.estimateBudgetAccountingManage.service;

import com.zhongwang.business.base.BaseService;
import com.zhongwang.business.common.JsonResult;
import com.zhongwang.business.gen.entity.*;
import com.zhongwang.business.module.contractManage.model.ConContractMainModel;
import com.zhongwang.business.module.estimateBudgetAccountingManage.dao.AccountingDao;
import com.zhongwang.business.module.estimateBudgetAccountingManage.dao.GetDataDao;
import com.zhongwang.business.module.estimateBudgetAccountingManage.model.*;
import com.zhongwang.business.util.*;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;

/**
 * GetDataService
 * 数据获取业务逻辑层
 *
 * @author 徐一贺
 * @version 1.0
 * @date 2020/9/11 15:07
 */
@Log4j2
@Service
public class GetDataService extends BaseService {
    @Autowired
    private GetDataDao getDataDao;

    /**
     * findList
     * 获取数据
     *
     * @return java.util.List 结果
     * @author 徐一贺
     * @date 2020/9/14 9:15
     * @version 1.0
     */
    public List<GetMatDataModel> findList() {
        return getDataDao.findList();
    }

    /**
     * getMatData
     * 获取数据
     *
     * @return com.zhongwang.business.common.JsonResult 页面结果
     * @author 徐一贺
     * @date 2020/9/14 9:51
     * @version 1.0
     */
    public JsonResult getMatData() {
        JsonResult jsonResult = new JsonResult();
        try {
            GetMatDataModel getMatDataModel = new GetMatDataModel();
            getMatDataModel.setGetDate(new Date());
            getMatDataModel.setGetUid(ShiroUtils.getUserId());
            //清除掉被替换的数据
            getDataDao.deleteDataFromPdmAndMms(getMatDataModel);
            //获取PDM系统与物资管理系统联查的数据并插入到商务系统材料表
            getDataDao.insertDataFromPdmAndMms(getMatDataModel);
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("获取成功！");
        } catch (Exception ex) {
            ex.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("获取失败！");
        }
        return jsonResult;
    }

    /**
     * generateOrderData
     * 根据项目号生成该项目下的数据源信息, 并返回
     *
     * @param code 项目号
     * @author 徐一贺
     * @date 2020/9/16 12:54
     * @version 1.0
     */
    @Transactional(rollbackFor = Exception.class)
    public void generateOrderData(String code) {
        ProjectModel projectModel = getDataDao.getProjectModel(code);
        BusBudgetAccountingTask abBudgetAccountingTask = getDataDao.getAbBudgetAccountingTaskByCodeAndTaskType(code, 2);
        //判断如果该项目下该任务下有数据源信息则不创建数据源项
        List<BusDataSourceModel> dataSourceList = getDataDao.findBusDataSourceModelListByBatId(abBudgetAccountingTask.getId());
        if (dataSourceList.size() > 0) {
            return;
        }
        List<VwDsnProStrucModel> vwDsnProStrucModelList = getDataDao.findPartInfoListByCode(code);
        if (vwDsnProStrucModelList.size() == 0) {
            return;
        }
        vwDsnProStrucModelList = adjustmentVwDsnProStrucModelList(vwDsnProStrucModelList);
        List<BusDataSourceTemplate> abDataSourceTemplateList = getDataDao.findDataSourceTemplateList();
        logService.saveLog("【核算管理-待核算项目】", "项目编号为" + projectModel.getCode() + "，项目名称为" + projectModel.getName() + "的项目，开始生成数据源信息！");
        for (VwDsnProStrucModel model : vwDsnProStrucModelList) {
            for (BusDataSourceTemplate templateModel : abDataSourceTemplateList) {
                if (templateModel.getType() != 0) {
                    if (("备品备件".equals(model.getProPart()) || "随机备件".equals(model.getProPart()) || "不可预见".equals(model.getProPart())) && "外购件".equals(templateModel.getName())) {
                        BusDataSource abDataSource = new BusDataSource();
                        abDataSource.setName(templateModel.getName());
                        abDataSource.setPart(model.getProPart());
                        abDataSource.setBatId(abBudgetAccountingTask.getId());
                        abDataSource.setSource(templateModel.getSource());
                        abDataSource.setDataCode(templateModel.getDataCode());
                        abDataSource.setOrderNo(templateModel.getOrderNo());
                        abDataSource.setType(templateModel.getType());
                        abDataSource.setDept(templateModel.getDept());
                        abDataSource.setMajor(model.getSpecial());
                        abDataSource.setUseType(templateModel.getUseType());
                        abDataSource.setReceiveStatus(0);
                        getDataDao.insertAbDataSource(abDataSource);
                        Map<String, String> fieldMap = new HashMap<>();
                        fieldMap.put("name", "数据名称");
                        fieldMap.put("part", "部分");
                        fieldMap.put("dept", "填报部门");
                        String log = LogFormatUtil.getInsertResult("项目编号为" + projectModel.getCode() + "，项目名称为" + projectModel.getName() + "的项目生成数据源信息", fieldMap, abDataSource);
                        logService.saveLog("【核算管理-待核算项目】", log);
                    } else if ((!"备品备件".equals(model.getProPart()) && !"随机备件".equals(model.getProPart()) && !"不可预见".equals(model.getProPart()))) {
                        BusDataSource abDataSource = new BusDataSource();
                        abDataSource.setName(templateModel.getName());
                        abDataSource.setPart(model.getProPart());
                        abDataSource.setBatId(abBudgetAccountingTask.getId());
                        abDataSource.setSource(templateModel.getSource());
                        abDataSource.setDataCode(templateModel.getDataCode());
                        abDataSource.setOrderNo(templateModel.getOrderNo());
                        abDataSource.setType(templateModel.getType());
                        abDataSource.setDept(templateModel.getDept());
                        abDataSource.setMajor(model.getSpecial());
                        abDataSource.setUseType(templateModel.getUseType());
                        getDataDao.insertAbDataSource(abDataSource);
                        Map<String, String> fieldMap = new HashMap<>();
                        fieldMap.put("name", "数据名称");
                        fieldMap.put("part", "部分");
                        fieldMap.put("dept", "填报部门");
                        String log = LogFormatUtil.getInsertResult("项目编号为" + projectModel.getCode() + "，项目名称为" + projectModel.getName() + "的项目生成数据源信息", fieldMap, abDataSource);
                        logService.saveLog("【核算管理-待核算项目】", log);
                    }

                }
            }
        }
        for (BusDataSourceTemplate templateModel : abDataSourceTemplateList) {
            if (templateModel.getType() == 0) {
                BusDataSource abDataSource = new BusDataSource();
                abDataSource.setName(templateModel.getName());
                abDataSource.setBatId(abBudgetAccountingTask.getId());
                abDataSource.setSource(templateModel.getSource());
                abDataSource.setDataCode(templateModel.getDataCode());
                abDataSource.setOrderNo(templateModel.getOrderNo());
                abDataSource.setType(templateModel.getType());
                abDataSource.setDept(templateModel.getDept());
                abDataSource.setUseType(templateModel.getUseType());
                getDataDao.insertAbDataSource(abDataSource);
                Map<String, String> fieldMap = new HashMap<>();
                fieldMap.put("name", "数据名称");
                fieldMap.put("part", "部分");
                fieldMap.put("dept", "填报部门");
                String log = LogFormatUtil.getInsertResult("项目编号为" + projectModel.getCode() + "，项目名称为" + projectModel.getName() + "的项目生成数据源信息", fieldMap, abDataSource);
                logService.saveLog("【核算管理-待核算项目】", log);
            }
        }
        logService.saveLog("【核算管理-待核算项目】", "项目编号为" + projectModel.getCode() + "，项目名称为" + projectModel.getName() + "的项目，生成数据源信息完毕！");
    }

    /**
     * adjustmentVwDsnProStrucModelList
     * 调整部分列表，每个专业增加 随机备件 备品备件 售后列表项
     *
     * @param vwDsnProStrucModelList 被处理的集合数据
     * @return java.util.List<com.zhongwang.business.module.estimateBudgetAccountingManage.model.VwDsnProStrucModel>
     * @author 徐一贺
     * @date 2020/11/3 20:53
     * @version 1.0
     */
    private List<VwDsnProStrucModel> adjustmentVwDsnProStrucModelList(List<VwDsnProStrucModel> vwDsnProStrucModelList) {
        List<String> majorList = new ArrayList<>();
        //获取专业
        for (VwDsnProStrucModel model : vwDsnProStrucModelList) {
            if (!majorList.contains(model.getSpecial())) {
                majorList.add(model.getSpecial());
            }
        }

        if (majorList.contains("机械")) {
            //机械随机备件
            VwDsnProStrucModel macRandomSpareParts = new VwDsnProStrucModel();
            macRandomSpareParts.setSpecial("机械");
            macRandomSpareParts.setProPart("随机备件");
            vwDsnProStrucModelList.add(macRandomSpareParts);
            //机械备品备件
            VwDsnProStrucModel macSpareParts = new VwDsnProStrucModel();
            macSpareParts.setSpecial("机械");
            macSpareParts.setProPart("备品备件");
            vwDsnProStrucModelList.add(macSpareParts);
            //机械售后
            VwDsnProStrucModel macAfterSale = new VwDsnProStrucModel();
            macAfterSale.setSpecial("机械");
            macAfterSale.setProPart("不可预见");
            vwDsnProStrucModelList.add(macAfterSale);
            //流体随机备件
        }
        if (majorList.contains("流体")) {
            VwDsnProStrucModel fluidRandomSpareParts = new VwDsnProStrucModel();
            fluidRandomSpareParts.setSpecial("流体");
            fluidRandomSpareParts.setProPart("随机备件");
            vwDsnProStrucModelList.add(fluidRandomSpareParts);
            //流体备品备件
            VwDsnProStrucModel fluidSpareParts = new VwDsnProStrucModel();
            fluidSpareParts.setSpecial("流体");
            fluidSpareParts.setProPart("备品备件");
            vwDsnProStrucModelList.add(fluidSpareParts);
            //流体售后
            VwDsnProStrucModel fluidAfterSale = new VwDsnProStrucModel();
            fluidAfterSale.setSpecial("流体");
            fluidAfterSale.setProPart("不可预见");
            vwDsnProStrucModelList.add(fluidAfterSale);
        }
        if (majorList.contains("自动化")) {
            //自动化随机备件
            VwDsnProStrucModel automationRandomSpareParts = new VwDsnProStrucModel();
            automationRandomSpareParts.setSpecial("自动化");
            automationRandomSpareParts.setProPart("随机备件");
            vwDsnProStrucModelList.add(automationRandomSpareParts);
            //自动化备品备件
            VwDsnProStrucModel automationSpareParts = new VwDsnProStrucModel();
            automationSpareParts.setSpecial("自动化");
            automationSpareParts.setProPart("备品备件");
            vwDsnProStrucModelList.add(automationSpareParts);
            //自动化售后
            VwDsnProStrucModel automationAfterSale = new VwDsnProStrucModel();
            automationAfterSale.setSpecial("自动化");
            automationAfterSale.setProPart("不可预见");
            vwDsnProStrucModelList.add(automationAfterSale);
        }
        return vwDsnProStrucModelList;
    }


    /**
     * findAccountingDataSourceList
     * 获取核算数据源列表
     *
     * @param param 检索参数
     * @return AbDataSource 数据
     * @author 徐一贺
     * @date 2020/9/16 19:14
     * @version 1.0
     */
    public List<AbDataSourceModel> findAccountingDataSourceList(AbDataSourceModel param) {
        return getDataDao.findAccountingDataSourceList(param);
    }

    /**
     * findAccountingDataSourceList
     * 获取核算数据源列表
     *
     * @param param 检索参数
     * @return AbDataSource 数据
     * @author 徐一贺
     * @date 2020/9/16 19:14
     * @version 1.0
     */
    public List<BusDataSourceModel> findAccountingDataSourceListByItem(AbDataSourceModel param) {
        return getDataDao.findAccountingDataSourceListByItem(param);
    }

    /**
     * getProjectModel
     * 根据项目编号从项目看板系统的项目信息视图中获取对应的项目信息
     *
     * @param code 项目编号
     * @return ProjectModel 项目信息
     * @author 徐一贺
     * @date 2020/9/17 10:23
     * @version 1.0
     */
    public ProjectModel getProjectModel(String code) {
        return getDataDao.getProjectModel(code);
    }

    /**
     * getDataBySystem
     * 依据类别、主键集合和主单据ID获取对应的数据
     *
     * @param param 类别、主键集合和主单据ID
     * @return JsonResult 获取结果
     * @author 徐一贺
     * @date 2020/9/17 10:48
     * @version 1.0
     */
//    @Transactional(rollbackFor = Exception.class)
    public JsonResult getDataBySystem(BusDataSourceModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            BusDataSourceModel dataSource = getDataDao.getBusDataSourceModelByPrimaryKey(param.getId());
            Date currentDate = new Date();
            BusBudgetAccountingTask busBudgetAccountingTask = getDataDao.getAbBudgetAccountingTaskByPrimaryKey(dataSource.getBatId());
            BusDataSourceModel dataSourceCondition = new BusDataSourceModel();
            dataSourceCondition.setBatId(dataSource.getBatId());
            List<BusDataSourceModel> dataSourceList = new ArrayList<>();
            //如果是从技术文件系统和物资管理系统获取材料数据
            if ("ds014".equals(dataSource.getDataCode())) {
                List<String> dataCodeList = new ArrayList<>();
                dataCodeList.add("ds002");
                dataCodeList.add("ds003");
                dataCodeList.add("ds004");
                dataSourceCondition.setDataCodeList(dataCodeList);
                dataSourceList = getDataDao.findBusDataSourceModelListByBatIdAndDataCodeList(dataSourceCondition);
                for (BusDataSourceModel dataSourceModel : dataSourceList) {
                    GetMatDataModel getMatDataModel = new GetMatDataModel();
                    getMatDataModel.setGetDate(currentDate);
                    getMatDataModel.setGetUid(ShiroUtils.getUserId());
                    getMatDataModel.setBatId(busBudgetAccountingTask.getId());
                    getMatDataModel.setDsId(dataSourceModel.getId());
                    getMatDataModel.setMajor(dataSourceModel.getMajor());
                    getMatDataModel.setPart(dataSourceModel.getPart());
                    getMatDataModel.setDataUseType(2);
                    //清除掉被替换的数据
                    getDataDao.deleteDataFromPdmAndMms(getMatDataModel);
                    dataSourceModel.setReceiveStatus(0);
                    dataSourceModel.setReceiveDate(null);
                    dataSourceModel.setSource(null);
                    getDataDao.updateDataSourceReceiveInfo(dataSourceModel);
                }
                for (BusDataSourceModel dataSourceModel : dataSourceList) {
                    if (dataSourceModel.getDataStatus() == null || dataSourceModel.getDataStatus() != 2) {
                        GetMatDataModel getMatDataModel = new GetMatDataModel();
                        getMatDataModel.setGetDate(currentDate);
                        getMatDataModel.setGetUid(ShiroUtils.getUserId());
                        getMatDataModel.setBatId(busBudgetAccountingTask.getId());
                        getMatDataModel.setDsId(dataSourceModel.getId());
                        getMatDataModel.setMajor(dataSourceModel.getMajor());
                        //获取PDM系统与物资管理系统联查的数据并插入到商务系统材料表
                        //如果是外购件
                        if ("ds002".equals(dataSourceModel.getDataCode())) {
                            getMatDataModel.setReportType(1);
                        }
                        //如果是原材料
                        else if ("ds003".equals(dataSourceModel.getDataCode())) {
                            getMatDataModel.setReportType(3);
                        }
//                    //如果是带料外协
//                    else if ("ds005".equals(dataSourceModel.getDataCode())) {
//                        getMatDataModel.setReportType(2);
//                        getMatDataModel.setAssistType("带料外协");
//                    }
                        //如果是外协
                        else if ("ds004".equals(dataSourceModel.getDataCode())) {
                            getMatDataModel.setReportType(2);
                            getMatDataModel.setAssistType("外协");
                        }
                        getMatDataModel.setPart(dataSourceModel.getPart());
                        getMatDataModel.setCode(busBudgetAccountingTask.getProCode());
                        int result = getDataDao.insertDataFromPdmAndMms(getMatDataModel);
                        if (result > 0) {
                            dataSourceModel.setDataStatus(3);
                            dataSourceModel.setReceiveStatus(1);
                            dataSourceModel.setReceiveDate(currentDate);
                            dataSourceModel.setSource("物资管理系统");
                            getDataDao.updateDataSourceReceiveInfo(dataSourceModel);
                            dataSource.setDataStatus(3);
                            dataSource.setReceiveStatus(1);
                            dataSource.setReceiveDate(currentDate);
                            dataSource.setSource("物资管理系统");
                            getDataDao.updateDataSourceReceiveInfo(dataSource);
                        } else {
                            dataSourceModel.setDataStatus(null);
                            dataSourceModel.setReceiveStatus(null);
                            dataSourceModel.setReceiveDate(null);
                            dataSourceModel.setSource(null);
                            getDataDao.updateDataSourceReceiveInfo(dataSourceModel);
                        }
                    }
                }
            }
            //如果是从技术文件系统获取设计工时、调试工时、结构净重、结构总重、机加工时
            else if ("ds015".equals(dataSource.getDataCode())) {
                List<String> dataCodeList = new ArrayList<>();
                dataCodeList.add("ds001");
                dataCodeList.add("ds008");
                dataSourceCondition.setDataCodeList(dataCodeList);
                dataSourceList = getDataDao.findBusDataSourceModelListByBatIdAndDataCodeList(dataSourceCondition);
                for (BusDataSourceModel dataSourceModel : dataSourceList) {
                    if (dataSourceModel.getDataStatus() == null || dataSourceModel.getDataStatus() != 2) {
                        //获取设计工时、调试工时、结构总重、结构净重
                        if ("ds001".equals(dataSourceModel.getDataCode())) {
                            //清空数据
                            BusGeneralHoursModel clearGeneralHoursData = new BusGeneralHoursModel();
                            clearGeneralHoursData.setBatId(busBudgetAccountingTask.getId());
                            clearGeneralHoursData.setTypes("1,2,3");
                            clearGeneralHoursData.setLaborTypes("1,2,3,20");
                            clearGeneralHoursData.setDataUseType(2);
                            clearGeneralHoursData.setMajor(dataSourceModel.getMajor());
                            clearGeneralHoursData.setPart(dataSourceModel.getPart());
                            clearGeneralHoursData.setDataUseType(2);
                            clearGeneralHoursData.setProCode(busBudgetAccountingTask.getProCode());
                            getDataDao.deleteBusGeneralHoursByclearGeneralHoursData(clearGeneralHoursData);
                            VwPdmWorkingHoursModel designWorkingHoursCondition = new VwPdmWorkingHoursModel();
                            designWorkingHoursCondition.setProCode(busBudgetAccountingTask.getProCode());
                            designWorkingHoursCondition.setCostType(1);
                            designWorkingHoursCondition.setIsDel(0);
                            designWorkingHoursCondition.setStatus(3);
                            //获取设计工时
                            designWorkingHoursCondition.setDataType("人工工时");
                            designWorkingHoursCondition.setDescribe("设计工时");
                            designWorkingHoursCondition.setSpecial(dataSourceModel.getMajor());
                            List<VwPdmWorkingHoursModel> designWorkingHoursList = getDataDao.findDesignWorkingHoursListByCondition(designWorkingHoursCondition);
                            VwPdmWorkingHoursModel changeReceiveModel = new VwPdmWorkingHoursModel();
                            changeReceiveModel.setReceiveStatus(1);
                            changeReceiveModel.setReceiveTime(currentDate);
                            Set<Integer> sheetIdSet = new HashSet<>();
                            for (VwPdmWorkingHoursModel hoursModel : designWorkingHoursList) {
                                BusGeneralHours generalHoursData = new BusGeneralHours();
                                generalHoursData.setProCode(hoursModel.getProCode());
                                generalHoursData.setPart(hoursModel.getProPart());
                                if ("机械".equals(hoursModel.getSpecial())) {
                                    generalHoursData.setType(1);
                                } else if ("流体".equals(hoursModel.getSpecial())) {
                                    generalHoursData.setType(2);
                                } else if ("自动化".equals(hoursModel.getSpecial())) {
                                    generalHoursData.setType(3);
                                }
                                generalHoursData.setLaborType(1);
                                generalHoursData.setLaborName(hoursModel.getDescribe());
                                generalHoursData.setLaborNum(hoursModel.getQuantity());
                                generalHoursData.setUnit(hoursModel.getUnit());
                                generalHoursData.setRemark(hoursModel.getRemark());
                                generalHoursData.setBatId(busBudgetAccountingTask.getId());
                                generalHoursData.setDsId(dataSourceModel.getId());
                                generalHoursData.setPriceType(1);
                                generalHoursData.setDataUseType(2);
                                generalHoursData.setMajor(hoursModel.getSpecial());
                                generalHoursData.setGetDate(currentDate);
                                generalHoursData.setGetUid(ShiroUtils.getUserId());
                                generalHoursData.setPostName(hoursModel.getCreateName());
                                generalHoursData.setPostDept(hoursModel.getBranchName());
                                getDataDao.insertBusGeneralHours(generalHoursData);
                                sheetIdSet.add(hoursModel.getCosSheetId());
                            }
                            if (designWorkingHoursList.size() > 0) {
                                dataSourceModel.setDataStatus(3);
                                dataSourceModel.setReceiveStatus(1);
                                dataSourceModel.setReceiveDate(currentDate);
                                dataSourceModel.setSource("技术文件管理系统");
                                getDataDao.updateDataSourceReceiveInfo(dataSourceModel);
                                dataSource.setDataStatus(3);
                                dataSource.setReceiveStatus(1);
                                dataSource.setReceiveDate(currentDate);
                                dataSource.setSource("技术文件管理系统");
                                getDataDao.updateDataSourceReceiveInfo(dataSource);
                            }
                            //获取调试工时
                            designWorkingHoursCondition.setCostType(8);
                            designWorkingHoursCondition.setDataType("调试工时");
                            designWorkingHoursCondition.setDescribe("调试工时");
                            List<VwPdmWorkingHoursModel> debugWorkingHoursList = getDataDao.findDesignWorkingHoursListByCondition(designWorkingHoursCondition);
                            for (int i = 0; i < debugWorkingHoursList.size(); i++) {
                                VwPdmWorkingHoursModel hoursModel = debugWorkingHoursList.get(i);
                                BusGeneralHours generalHoursData = new BusGeneralHours();
                                generalHoursData.setProCode(hoursModel.getProCode());
                                generalHoursData.setPart(hoursModel.getProPart());
                                if ("机械".equals(hoursModel.getSpecial())) {
                                    generalHoursData.setType(1);
                                } else if ("流体".equals(hoursModel.getSpecial())) {
                                    generalHoursData.setType(2);
                                } else if ("自动化".equals(hoursModel.getSpecial())) {
                                    generalHoursData.setType(3);
                                }
                                generalHoursData.setLaborType(20);
                                generalHoursData.setLaborName(hoursModel.getDescribe());
                                generalHoursData.setLaborNum(hoursModel.getQuantity());
                                generalHoursData.setUnit(hoursModel.getUnit());
                                generalHoursData.setRemark(hoursModel.getRemark());
                                generalHoursData.setBatId(busBudgetAccountingTask.getId());
                                generalHoursData.setDsId(dataSourceModel.getId());
                                generalHoursData.setPriceType(1);
                                generalHoursData.setDataUseType(2);
                                generalHoursData.setMajor(hoursModel.getSpecial());
                                generalHoursData.setGetDate(currentDate);
                                generalHoursData.setGetUid(ShiroUtils.getUserId());
                                generalHoursData.setPostName(hoursModel.getCreateName());
                                generalHoursData.setPostDept(hoursModel.getBranchName());
                                getDataDao.insertBusGeneralHours(generalHoursData);
                                sheetIdSet.add(hoursModel.getCosSheetId());
                            }
                            if (debugWorkingHoursList.size() > 0) {
                                dataSourceModel.setDataStatus(3);
                                dataSourceModel.setReceiveStatus(1);
                                dataSourceModel.setReceiveDate(currentDate);
                                dataSourceModel.setSource("技术文件管理系统");
                                getDataDao.updateDataSourceReceiveInfo(dataSourceModel);
                                dataSource.setDataStatus(3);
                                dataSource.setReceiveStatus(1);
                                dataSource.setReceiveDate(currentDate);
                                dataSource.setSource("技术文件管理系统");
                                getDataDao.updateDataSourceReceiveInfo(dataSource);
                            }
                            //获取结构总重
                            designWorkingHoursCondition.setCostType(1);
                            designWorkingHoursCondition.setDataType("结构总重");
                            designWorkingHoursCondition.setDescribe("结构总重");
                            List<VwPdmWorkingHoursModel> structureTotalWeightList = getDataDao.findDesignWorkingHoursListByCondition(designWorkingHoursCondition);
                            for (int i = 0; i < structureTotalWeightList.size(); i++) {
                                VwPdmWorkingHoursModel hoursModel = structureTotalWeightList.get(i);
                                BusGeneralHours generalHoursData = new BusGeneralHours();
                                generalHoursData.setProCode(hoursModel.getProCode());
                                generalHoursData.setPart(hoursModel.getProPart());
                                if ("机械".equals(hoursModel.getSpecial())) {
                                    generalHoursData.setType(1);
                                } else if ("流体".equals(hoursModel.getSpecial())) {
                                    generalHoursData.setType(2);
                                } else if ("自动化".equals(hoursModel.getSpecial())) {
                                    generalHoursData.setType(3);
                                }
                                generalHoursData.setLaborType(3);
                                generalHoursData.setLaborName(hoursModel.getDescribe());
                                generalHoursData.setLaborNum(hoursModel.getQuantity());
                                generalHoursData.setUnit(hoursModel.getUnit());
                                generalHoursData.setRemark(hoursModel.getRemark());
                                generalHoursData.setBatId(busBudgetAccountingTask.getId());
                                generalHoursData.setDsId(dataSourceModel.getId());
                                generalHoursData.setPriceType(1);
                                generalHoursData.setDataUseType(2);
                                generalHoursData.setMajor(hoursModel.getSpecial());
                                generalHoursData.setGetDate(currentDate);
                                generalHoursData.setGetUid(ShiroUtils.getUserId());
                                generalHoursData.setPostName(hoursModel.getCreateName());
                                generalHoursData.setPostDept(hoursModel.getBranchName());
                                getDataDao.insertBusGeneralHours(generalHoursData);
                                sheetIdSet.add(hoursModel.getCosSheetId());
                            }
                            if (structureTotalWeightList.size() > 0) {
                                dataSourceModel.setDataStatus(3);
                                dataSourceModel.setReceiveStatus(1);
                                dataSourceModel.setReceiveDate(currentDate);
                                dataSourceModel.setSource("技术文件管理系统");
                                getDataDao.updateDataSourceReceiveInfo(dataSourceModel);
                                dataSource.setDataStatus(3);
                                dataSource.setReceiveStatus(1);
                                dataSource.setReceiveDate(currentDate);
                                dataSource.setSource("技术文件管理系统");
                                getDataDao.updateDataSourceReceiveInfo(dataSource);
                            }
                            //获取结构净重
                            designWorkingHoursCondition.setDataType("结构净重");
                            designWorkingHoursCondition.setDescribe(null);
                            List<VwPdmWorkingHoursModel> structureNetWeightList = getDataDao.findDesignWorkingHoursListByCondition(designWorkingHoursCondition);
                            for (int i = 0; i < structureNetWeightList.size(); i++) {
                                VwPdmWorkingHoursModel hoursModel = structureNetWeightList.get(i);
                                BusGeneralHours generalHoursData = new BusGeneralHours();
                                generalHoursData.setProCode(hoursModel.getProCode());
                                generalHoursData.setPart(hoursModel.getProPart());
                                if ("机械".equals(hoursModel.getSpecial())) {
                                    generalHoursData.setType(1);
                                } else if ("流体".equals(hoursModel.getSpecial())) {
                                    generalHoursData.setType(2);
                                } else if ("自动化".equals(hoursModel.getSpecial())) {
                                    generalHoursData.setType(3);
                                }
                                generalHoursData.setLaborType(2);
                                generalHoursData.setLaborName(hoursModel.getDescribe());
                                generalHoursData.setLaborNum(hoursModel.getQuantity());
                                generalHoursData.setUnit(hoursModel.getUnit());
                                generalHoursData.setRemark(hoursModel.getRemark());
                                generalHoursData.setBatId(busBudgetAccountingTask.getId());
                                generalHoursData.setDsId(dataSourceModel.getId());
                                generalHoursData.setPriceType(1);
                                generalHoursData.setDataUseType(2);
                                generalHoursData.setMajor(hoursModel.getSpecial());
                                generalHoursData.setGetDate(currentDate);
                                generalHoursData.setGetUid(ShiroUtils.getUserId());
                                generalHoursData.setPostName(hoursModel.getCreateName());
                                generalHoursData.setPostDept(hoursModel.getBranchName());
                                getDataDao.insertBusGeneralHours(generalHoursData);
                                sheetIdSet.add(hoursModel.getCosSheetId());
                            }
                            if (structureNetWeightList.size() > 0) {
                                dataSourceModel.setDataStatus(3);
                                dataSourceModel.setReceiveStatus(1);
                                dataSourceModel.setReceiveDate(currentDate);
                                dataSourceModel.setSource("技术文件管理系统");
                                getDataDao.updateDataSourceReceiveInfo(dataSourceModel);
                                dataSource.setDataStatus(3);
                                dataSource.setReceiveStatus(1);
                                dataSource.setReceiveDate(currentDate);
                                dataSource.setSource("技术文件管理系统");
                                getDataDao.updateDataSourceReceiveInfo(dataSource);
                            }
                            if (sheetIdSet.size() > 0) {
                                changeReceiveModel.setCosSheetIds(sheetIdSet.toString().replace("[", "").replace("]", ""));
                                getDataDao.updateVwCosSheetByChangeReceiveModel(changeReceiveModel);
                            }
                        }
                        //如果是机加数据源
                        else if ("ds008".equals(dataSourceModel.getDataCode())) {
                            //清空数据
                            BusMachiningHours clearDataModel = new BusMachiningHours();
                            clearDataModel.setBatId(busBudgetAccountingTask.getId());
                            clearDataModel.setMajor(dataSourceModel.getMajor());
                            clearDataModel.setPart(dataSourceModel.getPart());
                            clearDataModel.setDsId(dataSourceModel.getId());
                            clearDataModel.setProCode(busBudgetAccountingTask.getProCode());
                            clearDataModel.setDataUseType(2);
                            clearDataModel.setType(2);
                            getDataDao.deleteBusMachiningHoursByCondition(clearDataModel);
                            VwMachiningModel machiningCondition = new VwMachiningModel();
                            machiningCondition.setProCode(busBudgetAccountingTask.getProCode());
                            machiningCondition.setSpecial(dataSourceModel.getMajor());
                            machiningCondition.setPart(dataSourceModel.getPart());
                            List<VwMachiningModel> machiningModelList = getDataDao.findVwMachiningModelListByCondition(machiningCondition);
                            for (VwMachiningModel machiningModel : machiningModelList) {
                                BusMachiningHours busMachiningHoursData = new BusMachiningHours();
                                busMachiningHoursData.setBatId(busBudgetAccountingTask.getId());
                                busMachiningHoursData.setProCode(busBudgetAccountingTask.getProCode());
                                busMachiningHoursData.setDiagram(machiningModel.getDrawNo());
                                busMachiningHoursData.setDrawingNo(machiningModel.getDrawName());
                                busMachiningHoursData.setNum(new BigDecimal(machiningModel.getDrawNum()));
                                busMachiningHoursData.setDataUseType(2);
                                busMachiningHoursData.setType(2);
                                busMachiningHoursData.setProcess(machiningModel.getProcess());
                                busMachiningHoursData.setPart(machiningModel.getPart());
                                busMachiningHoursData.setDsId(dataSourceModel.getId());
                                busMachiningHoursData.setGetDate(currentDate);
                                busMachiningHoursData.setGetUid(ShiroUtils.getUserId());
                                String bmeCode = getDataDao.getMachiningEquipmentCodeByModel(machiningModel);
                                busMachiningHoursData.setBmeCode(bmeCode);
                                busMachiningHoursData.setPostName(machiningModel.getCreateCodeTwo() == null ? machiningModel.getCreateNameOne() : machiningModel.getCreateCodeTwo());
                                busMachiningHoursData.setPostTel(machiningModel.getCreateTel());
                                busMachiningHoursData.setPostDept(machiningModel.getDeptName());
                                busMachiningHoursData.setMajor(machiningModel.getSpecial());
                                //处理工时相加
                                BigDecimal readyHours = machiningModel.getWorkTimeOne();
                                if (readyHours == null) {
                                    readyHours = new BigDecimal(0);
                                }
                                BigDecimal machiningHours = machiningModel.getWorkTimeTwo();
                                if (machiningHours == null) {
                                    machiningHours = new BigDecimal(0);
                                }
                                //结果
                                BigDecimal result = new BigDecimal(0);
                                BigDecimal integerOne = new BigDecimal(0);
                                BigDecimal decimalOne = new BigDecimal(0);
                                BigDecimal ready = new BigDecimal(0);
                                BigDecimal integerTwo = new BigDecimal(0);
                                BigDecimal decimalTwo = new BigDecimal(0);
                                BigDecimal machining = new BigDecimal(0);
                                //获取整数
                                if (readyHours.toString().contains(".")) {
                                    integerOne = new BigDecimal(readyHours.toString().substring(0, readyHours.toString().indexOf(".")));
                                    decimalOne = new BigDecimal(readyHours.toString().substring(readyHours.toString().indexOf(".") + 1));
                                } else {
                                    ready = readyHours;
                                }
                                if (machiningHours.toString().contains(".")) {
                                    integerTwo = new BigDecimal(machiningHours.toString().substring(0, machiningHours.toString().indexOf(".")));
                                    decimalTwo = new BigDecimal(machiningHours.toString().substring(machiningHours.toString().indexOf(".") + 1));
                                } else {
                                    machining = machiningHours;
                                }

                                if (readyHours.toString().contains(".") || machiningHours.toString().contains(".")) {
                                    result = integerOne.add(integerTwo);
                                    if (decimalOne.add(decimalTwo).compareTo(new BigDecimal(0.6)) == 1) {
                                        result = result.add(new BigDecimal(1)).add(decimalOne.add(decimalTwo).subtract(new BigDecimal(0.6)));
                                    } else {
                                        result = result.add(decimalOne.add(decimalTwo).subtract(new BigDecimal(0.6)));
                                    }
                                }else{
                                    result = ready.add(machining);
                                }
                                busMachiningHoursData.setHours(result);
                                busMachiningHoursData.setName(machiningModel.getEquName());
                                getDataDao.insertBusMachiningHours(busMachiningHoursData);
                            }
                            if (machiningModelList.size() > 0) {
                                dataSourceModel.setDataStatus(3);
                                dataSourceModel.setReceiveStatus(1);
                                dataSourceModel.setReceiveDate(currentDate);
                                dataSourceModel.setSource("生产管理系统");
                                getDataDao.updateDataSourceReceiveInfo(dataSourceModel);
                                dataSource.setDataStatus(3);
                                dataSource.setReceiveStatus(1);
                                dataSource.setReceiveDate(currentDate);
                                dataSource.setSource("生产管理系统");
                                getDataDao.updateDataSourceReceiveInfo(dataSource);
                            }
                        }
                    }

                }
            }
            //版本1.0：单项获取
            //版本2.0：一次性从本地表获取
            //版本3.0：因本地表结构删除所以重新修改数据获取
            //如果是从商务系统获取下料工时、下料辅材、铆焊工时、铆焊辅材、热处理重量、涂装工时、涂装辅材、装配工时、装配辅材、包装工时、包装辅材、运输费、安装工时、安装辅材
            else if ("ds016".equals(dataSource.getDataCode())) {
                List<String> dataCodeList = new ArrayList<>();
                dataCodeList.add("ds006");
                dataCodeList.add("ds007");
                dataCodeList.add("ds009");
                dataCodeList.add("ds010");
                dataCodeList.add("ds011");
                dataCodeList.add("ds012");
                dataCodeList.add("ds013");
                dataSourceCondition.setDataCodeList(dataCodeList);
                dataSourceList = getDataDao.findBusDataSourceModelListByBatIdAndDataCodeList(dataSourceCondition);
                String dataSourceText = "商务系统";
                for (BusDataSourceModel dataSourceModel : dataSourceList) {
                    if (dataSourceModel.getDataStatus() == null || dataSourceModel.getDataStatus() != 2) {
                        //获取下料
                        if ("ds006".equals(dataSourceModel.getDataCode())) {
                            //实际工时
                            CosSheetModel condition = new CosSheetModel();
                            condition.setProCode(busBudgetAccountingTask.getProCode());
                            condition.setSpecial(dataSourceModel.getMajor());
                            condition.setCostType((byte) 2);
                            condition.setProPart(dataSourceModel.getPart());
                            condition.setIsDel((byte) 0);
                            condition.setStatus((byte) 3);
                            condition.setDataType("人工工时");
                            //根据条件清空数据
                            BusGeneralHoursModel busCondition = new BusGeneralHoursModel();
                            busCondition.setMajor(dataSourceModel.getMajor());
                            busCondition.setBatId(busBudgetAccountingTask.getId());
                            if ("机械".equals(dataSourceModel.getMajor())) {
                                busCondition.setType(7);
                            }
                            if ("流体".equals(dataSourceModel.getMajor())) {
                                busCondition.setType(8);
                            }
                            if ("自动化".equals(dataSourceModel.getMajor())) {
                                busCondition.setType(9);
                            }
                            busCondition.setLaborType(4);
                            busCondition.setDataUseType(2);
                            busCondition.setPart(dataSourceModel.getPart());
                            busCondition.setDsId(dataSourceModel.getId());
                            getDataDao.deleteBusGeneralHoursByConditionModel(busCondition);
                            List<CosSheetModel> cuttingList = getDataDao.findCosManufactureModelList(condition);
                            for (CosSheetModel cosSheetModel : cuttingList) {
                                BusGeneralHours busGeneralHours = new BusGeneralHours();
                                busGeneralHours.setProCode(busBudgetAccountingTask.getProCode());
                                busGeneralHours.setPart(dataSourceModel.getPart());
                                if ("机械".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(7);
                                }
                                if ("流体".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(8);
                                }
                                if ("自动化".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(9);
                                }
                                busGeneralHours.setLaborType(4);
                                busGeneralHours.setLaborNum(cosSheetModel.getQuantity());
                                busGeneralHours.setLaborName(cosSheetModel.getDescribe());
                                busGeneralHours.setUnit(cosSheetModel.getUnit());
                                busGeneralHours.setRemark(cosSheetModel.getRemark());
                                busGeneralHours.setBatId(busBudgetAccountingTask.getId());
                                busGeneralHours.setPlaceDelivery(null);
                                busGeneralHours.setDestination(null);
                                //机械工程部平均日工资
                                BigDecimal price = getDataDao.getConfigTemplatePriceByCode("Average daily wage per capita of Zhongwang machinery");
                                busGeneralHours.setPrice(price);
                                busGeneralHours.setDsId(dataSourceModel.getId());
                                busGeneralHours.setPriceType(1);
                                busGeneralHours.setDataUseType(2);
                                busGeneralHours.setMajor(dataSourceModel.getMajor());
                                busGeneralHours.setGetDate(currentDate);
                                busGeneralHours.setAmount(busGeneralHours.getLaborNum().multiply(busGeneralHours.getPrice()));
                                busGeneralHours.setGetUid(ShiroUtils.getUserId());
                                busGeneralHours.setPostDept(cosSheetModel.getBranchName());
                                busGeneralHours.setPostName(cosSheetModel.getCreateName());
                                getDataDao.insertBusGeneralHours(busGeneralHours);
                                cosSheetModel.setReceiveStatus((byte) 1);
                                cosSheetModel.setReceiveTime(currentDate);
                                getDataDao.updateCosSheetModelReceiveInfoByPrimaryKey(cosSheetModel);
                            }
                            //辅材
                            //清空辅材信息
                            BusGeneralHoursModel bghCondition = new BusGeneralHoursModel();
                            bghCondition.setMajor(dataSourceModel.getMajor());
                            if ("机械".equals(dataSourceModel.getMajor())) {
                                bghCondition.setType(7);
                            }
                            if ("流体".equals(dataSourceModel.getMajor())) {
                                bghCondition.setType(8);
                            }
                            if ("自动化".equals(dataSourceModel.getMajor())) {
                                bghCondition.setType(9);
                            }
                            bghCondition.setLaborType(5);
                            bghCondition.setBatId(busBudgetAccountingTask.getId());
                            bghCondition.setPart(dataSourceModel.getPart());
                            bghCondition.setDataUseType(2);
                            bghCondition.setDsId(dataSourceModel.getId());
                            getDataDao.deleteBusGeneralHoursByConditionModel(bghCondition);
                            //获取辅材数据
                            CosSheetModel auxiliaryMaterialsCondition = new CosSheetModel();
                            auxiliaryMaterialsCondition.setProCode(busBudgetAccountingTask.getProCode());
                            auxiliaryMaterialsCondition.setSpecial(dataSourceModel.getMajor());
                            auxiliaryMaterialsCondition.setCostType((byte) 2);
                            auxiliaryMaterialsCondition.setProPart(dataSourceModel.getPart());
                            auxiliaryMaterialsCondition.setIsDel((byte) 0);
                            auxiliaryMaterialsCondition.setStatus((byte) 3);
                            auxiliaryMaterialsCondition.setDataType("主要辅材");
                            List<CosSheetModel> auxiliaryMaterialsList = getDataDao.findCosManufactureModelList(auxiliaryMaterialsCondition);
                            for (CosSheetModel auxiliaryMaterialsCosSheetModel : auxiliaryMaterialsList) {
                                BusGeneralHours busGeneralHours = new BusGeneralHours();
                                busGeneralHours.setProCode(busBudgetAccountingTask.getProCode());
                                busGeneralHours.setPart(dataSourceModel.getPart());
                                if ("机械".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(7);
                                }
                                if ("流体".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(8);
                                }
                                if ("自动化".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(9);
                                }
                                busGeneralHours.setLaborType(5);
                                busGeneralHours.setLaborNum(auxiliaryMaterialsCosSheetModel.getQuantity());
                                busGeneralHours.setLaborName(auxiliaryMaterialsCosSheetModel.getDescribe());
                                busGeneralHours.setUnit(auxiliaryMaterialsCosSheetModel.getUnit());
                                busGeneralHours.setRemark(auxiliaryMaterialsCosSheetModel.getRemark());
                                busGeneralHours.setBatId(busBudgetAccountingTask.getId());
                                busGeneralHours.setPlaceDelivery(null);
                                busGeneralHours.setDestination(null);
                                busGeneralHours.setPrice(null);
                                busGeneralHours.setDsId(dataSourceModel.getId());
                                busGeneralHours.setPriceType(1);
                                busGeneralHours.setDataUseType(2);
                                busGeneralHours.setMajor(dataSourceModel.getMajor());
                                busGeneralHours.setGetDate(currentDate);
                                busGeneralHours.setAmount(null);
                                busGeneralHours.setGetUid(ShiroUtils.getUserId());
                                busGeneralHours.setPostDept(auxiliaryMaterialsCosSheetModel.getBranchName());
                                busGeneralHours.setPostName(auxiliaryMaterialsCosSheetModel.getCreateName());
                                getDataDao.insertBusGeneralHours(busGeneralHours);
                                auxiliaryMaterialsCosSheetModel.setReceiveStatus((byte) 1);
                                auxiliaryMaterialsCosSheetModel.setReceiveTime(currentDate);
                                getDataDao.updateCosSheetModelReceiveInfoByPrimaryKey(auxiliaryMaterialsCosSheetModel);
                            }
                            if (auxiliaryMaterialsList.size() > 0 || cuttingList.size() > 0) {
                                if (auxiliaryMaterialsList.size() > 0) {
                                    dataSourceModel.setStaff(auxiliaryMaterialsList.get(0).getCreateName());
                                    dataSourceModel.setDept(auxiliaryMaterialsList.get(0).getBranchName());
                                    dataSourceModel.setAddDate(auxiliaryMaterialsList.get(0).getVerifyTime());
                                } else {
                                    dataSourceModel.setStaff(cuttingList.get(0).getCreateName());
                                    dataSourceModel.setDept(cuttingList.get(0).getBranchName());
                                    dataSourceModel.setAddDate(cuttingList.get(0).getVerifyTime());
                                }
                                dataSourceModel.setReceiveDate(currentDate);
                                dataSourceModel.setReceiveStatus(1);
                                dataSourceModel.setSource(dataSourceText);
                                dataSourceModel.setDataStatus(3);
                                getDataDao.updateDataSourceByPrimaryKeySelectivity(dataSourceModel);
                                dataSource.setDataStatus(3);
                                dataSource.setReceiveStatus(1);
                                dataSource.setReceiveDate(currentDate);
                                dataSource.setSource("生产管理系统");
                                getDataDao.updateDataSourceReceiveInfo(dataSource);
                            }
                        }
                        //铆焊
                        else if ("ds007".equals(dataSourceModel.getDataCode())) {
                            //实际工时
                            CosSheetModel condition = new CosSheetModel();
                            condition.setProCode(busBudgetAccountingTask.getProCode());
                            condition.setSpecial(dataSourceModel.getMajor());
                            condition.setCostType((byte) 3);
                            condition.setProPart(dataSourceModel.getPart());
                            condition.setIsDel((byte) 0);
                            condition.setStatus((byte) 3);
                            condition.setDataType("人工工时");
                            //根据条件清空数据
                            BusGeneralHoursModel busCondition = new BusGeneralHoursModel();
                            busCondition.setMajor(dataSourceModel.getMajor());
                            busCondition.setBatId(busBudgetAccountingTask.getId());
                            if ("机械".equals(dataSourceModel.getMajor())) {
                                busCondition.setType(13);
                            }
                            if ("流体".equals(dataSourceModel.getMajor())) {
                                busCondition.setType(14);
                            }
                            if ("自动化".equals(dataSourceModel.getMajor())) {
                                busCondition.setType(15);
                            }
                            busCondition.setLaborType(6);
                            busCondition.setDataUseType(2);
                            busCondition.setPart(dataSourceModel.getPart());
                            busCondition.setDsId(dataSourceModel.getId());
                            getDataDao.deleteBusGeneralHoursByConditionModel(busCondition);
                            List<CosSheetModel> rivetAndSolderList = getDataDao.findCosManufactureModelList(condition);
                            for (CosSheetModel rivetAndSolderCosSheetModel : rivetAndSolderList) {
                                BusGeneralHours busGeneralHours = new BusGeneralHours();
                                busGeneralHours.setProCode(busBudgetAccountingTask.getProCode());
                                busGeneralHours.setPart(dataSourceModel.getPart());
                                if ("机械".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(13);
                                }
                                if ("流体".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(14);
                                }
                                if ("自动化".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(15);
                                }
                                busGeneralHours.setLaborType(6);
                                busGeneralHours.setLaborNum(rivetAndSolderCosSheetModel.getQuantity());
                                busGeneralHours.setLaborName(rivetAndSolderCosSheetModel.getDescribe());
                                busGeneralHours.setUnit(rivetAndSolderCosSheetModel.getUnit());
                                busGeneralHours.setRemark(rivetAndSolderCosSheetModel.getRemark());
                                busGeneralHours.setBatId(busBudgetAccountingTask.getId());
                                busGeneralHours.setPlaceDelivery(null);
                                busGeneralHours.setDestination(null);
                                //机械工程部平均日工资
                                BigDecimal price = getDataDao.getConfigTemplatePriceByCode("Average daily wage per capita of Zhongwang machinery");
                                busGeneralHours.setPrice(price);
                                busGeneralHours.setDsId(dataSourceModel.getId());
                                busGeneralHours.setPriceType(1);
                                busGeneralHours.setDataUseType(2);
                                busGeneralHours.setMajor(dataSourceModel.getMajor());
                                busGeneralHours.setGetDate(currentDate);
                                busGeneralHours.setAmount(busGeneralHours.getLaborNum().multiply(busGeneralHours.getPrice()));
                                busGeneralHours.setGetUid(ShiroUtils.getUserId());
                                busGeneralHours.setPostDept(rivetAndSolderCosSheetModel.getBranchName());
                                busGeneralHours.setPostName(rivetAndSolderCosSheetModel.getCreateName());
                                getDataDao.insertBusGeneralHours(busGeneralHours);
                                rivetAndSolderCosSheetModel.setReceiveStatus((byte) 1);
                                rivetAndSolderCosSheetModel.setReceiveTime(currentDate);
                                getDataDao.updateCosSheetModelReceiveInfoByPrimaryKey(rivetAndSolderCosSheetModel);
                            }
                            //辅材
                            //清空辅材信息
                            BusGeneralHoursModel bghCondition = new BusGeneralHoursModel();
                            bghCondition.setMajor(dataSourceModel.getMajor());
                            if ("机械".equals(dataSourceModel.getMajor())) {
                                bghCondition.setType(13);
                            }
                            if ("流体".equals(dataSourceModel.getMajor())) {
                                bghCondition.setType(14);
                            }
                            if ("自动化".equals(dataSourceModel.getMajor())) {
                                bghCondition.setType(15);
                            }
                            bghCondition.setLaborType(7);
                            bghCondition.setBatId(busBudgetAccountingTask.getId());
                            bghCondition.setPart(dataSourceModel.getPart());
                            bghCondition.setDataUseType(2);
                            bghCondition.setDsId(dataSourceModel.getId());
                            getDataDao.deleteBusGeneralHoursByConditionModel(bghCondition);
                            //获取辅材数据
                            CosSheetModel auxiliaryMaterialsCondition = new CosSheetModel();
                            auxiliaryMaterialsCondition.setProCode(busBudgetAccountingTask.getProCode());
                            auxiliaryMaterialsCondition.setSpecial(dataSourceModel.getMajor());
                            auxiliaryMaterialsCondition.setCostType((byte) 3);
                            auxiliaryMaterialsCondition.setProPart(dataSourceModel.getPart());
                            auxiliaryMaterialsCondition.setIsDel((byte) 0);
                            auxiliaryMaterialsCondition.setStatus((byte) 3);
                            auxiliaryMaterialsCondition.setDataType("主要辅材");
                            List<CosSheetModel> auxiliaryMaterialsList = getDataDao.findCosManufactureModelList(auxiliaryMaterialsCondition);
                            for (CosSheetModel auxiliaryMaterialsCosSheetModel : auxiliaryMaterialsList) {
                                BusGeneralHours busGeneralHours = new BusGeneralHours();
                                busGeneralHours.setProCode(busBudgetAccountingTask.getProCode());
                                busGeneralHours.setPart(dataSourceModel.getPart());
                                if ("机械".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(13);
                                }
                                if ("流体".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(14);
                                }
                                if ("自动化".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(15);
                                }
                                busGeneralHours.setLaborType(7);
                                busGeneralHours.setLaborNum(auxiliaryMaterialsCosSheetModel.getQuantity());
                                busGeneralHours.setLaborName(auxiliaryMaterialsCosSheetModel.getDescribe());
                                busGeneralHours.setUnit(auxiliaryMaterialsCosSheetModel.getUnit());
                                busGeneralHours.setRemark(auxiliaryMaterialsCosSheetModel.getRemark());
                                busGeneralHours.setBatId(busBudgetAccountingTask.getId());
                                busGeneralHours.setPlaceDelivery(null);
                                busGeneralHours.setDestination(null);
                                busGeneralHours.setDsId(dataSourceModel.getId());
                                busGeneralHours.setPriceType(1);
                                busGeneralHours.setDataUseType(2);
                                busGeneralHours.setMajor(dataSourceModel.getMajor());
                                busGeneralHours.setGetDate(currentDate);
                                busGeneralHours.setAmount(null);
                                busGeneralHours.setGetUid(ShiroUtils.getUserId());
                                busGeneralHours.setPostDept(auxiliaryMaterialsCosSheetModel.getBranchName());
                                busGeneralHours.setPostName(auxiliaryMaterialsCosSheetModel.getCreateName());
                                getDataDao.insertBusGeneralHours(busGeneralHours);
                                auxiliaryMaterialsCosSheetModel.setReceiveStatus((byte) 1);
                                auxiliaryMaterialsCosSheetModel.setReceiveTime(currentDate);
                                getDataDao.updateCosSheetModelReceiveInfoByPrimaryKey(auxiliaryMaterialsCosSheetModel);
                            }
                            if (auxiliaryMaterialsList.size() > 0 || rivetAndSolderList.size() > 0) {
                                if (auxiliaryMaterialsList.size() > 0) {
                                    dataSourceModel.setStaff(auxiliaryMaterialsList.get(0).getCreateName());
                                    dataSourceModel.setDept(auxiliaryMaterialsList.get(0).getBranchName());
                                    dataSourceModel.setAddDate(auxiliaryMaterialsList.get(0).getVerifyTime());
                                } else {
                                    dataSourceModel.setStaff(rivetAndSolderList.get(0).getCreateName());
                                    dataSourceModel.setDept(rivetAndSolderList.get(0).getBranchName());
                                    dataSourceModel.setAddDate(rivetAndSolderList.get(0).getVerifyTime());
                                }
                                dataSourceModel.setReceiveDate(currentDate);
                                dataSourceModel.setReceiveStatus(1);
                                dataSourceModel.setSource(dataSourceText);
                                dataSourceModel.setDataStatus(3);
                                getDataDao.updateDataSourceByPrimaryKeySelectivity(dataSourceModel);
                                dataSource.setDataStatus(3);
                                dataSource.setReceiveStatus(1);
                                dataSource.setReceiveDate(currentDate);
                                dataSource.setSource("生产管理系统");
                                getDataDao.updateDataSourceReceiveInfo(dataSource);
                            }
                        }
                        //热处理工时
                        else if ("ds009".equals(dataSourceModel.getDataCode())) {
                            //实际工时
                            CosSheetModel condition = new CosSheetModel();
                            condition.setProCode(busBudgetAccountingTask.getProCode());
                            condition.setSpecial(dataSourceModel.getMajor());
                            condition.setCostType((byte) 4);
                            condition.setProPart(dataSourceModel.getPart());
                            condition.setIsDel((byte) 0);
                            condition.setStatus((byte) 3);
                            condition.setDataType("热处理");
                            //根据条件清空数据
                            BusGeneralHoursModel busCondition = new BusGeneralHoursModel();
                            busCondition.setMajor(dataSourceModel.getMajor());
                            busCondition.setBatId(busBudgetAccountingTask.getId());
                            if ("机械".equals(dataSourceModel.getMajor())) {
                                busCondition.setType(19);
                            }
                            if ("流体".equals(dataSourceModel.getMajor())) {
                                busCondition.setType(20);
                            }
                            if ("自动化".equals(dataSourceModel.getMajor())) {
                                busCondition.setType(21);
                            }
                            busCondition.setLaborType(8);
                            busCondition.setDataUseType(2);
                            busCondition.setPart(dataSourceModel.getPart());
                            busCondition.setDsId(dataSourceModel.getId());
                            getDataDao.deleteBusGeneralHoursByConditionModel(busCondition);
                            List<CosSheetModel> heatTreatmentList = getDataDao.findCosManufactureModelList(condition);
                            for (CosSheetModel heatTreatmentCosSheetModel : heatTreatmentList) {
                                BusGeneralHours busGeneralHours = new BusGeneralHours();
                                busGeneralHours.setProCode(busBudgetAccountingTask.getProCode());
                                busGeneralHours.setPart(dataSourceModel.getPart());
                                if ("机械".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(19);
                                }
                                if ("流体".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(20);
                                }
                                if ("自动化".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(21);
                                }
                                busGeneralHours.setLaborType(8);
                                busGeneralHours.setLaborNum(heatTreatmentCosSheetModel.getQuantity());
                                busGeneralHours.setLaborName(heatTreatmentCosSheetModel.getDescribe());
                                busGeneralHours.setUnit(heatTreatmentCosSheetModel.getUnit());
                                busGeneralHours.setRemark(heatTreatmentCosSheetModel.getRemark());
                                busGeneralHours.setBatId(busBudgetAccountingTask.getId());
                                busGeneralHours.setPlaceDelivery(null);
                                busGeneralHours.setDestination(null);
//                            //热处理
//                            BigDecimal price = getDataDao.getConfigTemplatePriceByCode("heat treatment");
//                            busGeneralHours.setPrice(price);
                                busGeneralHours.setDsId(dataSourceModel.getId());
                                busGeneralHours.setPriceType(1);
                                busGeneralHours.setDataUseType(2);
                                busGeneralHours.setMajor(dataSourceModel.getMajor());
                                busGeneralHours.setGetDate(currentDate);
                                busGeneralHours.setAmount(null);
                                busGeneralHours.setGetUid(ShiroUtils.getUserId());
                                busGeneralHours.setPostDept(heatTreatmentCosSheetModel.getBranchName());
                                busGeneralHours.setPostName(heatTreatmentCosSheetModel.getCreateName());
                                getDataDao.insertBusGeneralHours(busGeneralHours);
                                heatTreatmentCosSheetModel.setReceiveStatus((byte) 1);
                                heatTreatmentCosSheetModel.setReceiveTime(currentDate);
                                getDataDao.updateCosSheetModelReceiveInfoByPrimaryKey(heatTreatmentCosSheetModel);
                            }
                            //回写接收信息
                            if (heatTreatmentList.size() > 0) {
                                dataSourceModel.setStaff(heatTreatmentList.get(0).getCreateName());
                                dataSourceModel.setDept(heatTreatmentList.get(0).getBranchName());
                                dataSourceModel.setAddDate(heatTreatmentList.get(0).getVerifyTime());
                                dataSourceModel.setReceiveDate(currentDate);
                                dataSourceModel.setReceiveStatus(1);
                                dataSourceModel.setSource(dataSourceText);
                                dataSourceModel.setDataStatus(3);
                                getDataDao.updateDataSourceByPrimaryKeySelectivity(dataSourceModel);
                                dataSource.setDataStatus(3);
                                dataSource.setReceiveStatus(1);
                                dataSource.setReceiveDate(currentDate);
                                dataSource.setSource("生产管理系统");
                                getDataDao.updateDataSourceReceiveInfo(dataSource);
                            }
                        } //获取 涂装工时 辅材 两张表数据
                        else if ("ds010".equals(dataSourceModel.getDataCode())) {
                            //实际工时
                            CosSheetModel condition = new CosSheetModel();
                            condition.setProCode(busBudgetAccountingTask.getProCode());
                            condition.setSpecial(dataSourceModel.getMajor());
                            condition.setCostType((byte) 6);
                            condition.setProPart(dataSourceModel.getPart());
                            condition.setIsDel((byte) 0);
                            condition.setStatus((byte) 3);
                            condition.setDataTypes("'人工工时喷','人工工时涂'");
                            //根据条件清空数据
                            BusGeneralHoursModel busCondition = new BusGeneralHoursModel();
                            busCondition.setMajor(dataSourceModel.getMajor());
                            busCondition.setBatId(busBudgetAccountingTask.getId());
                            if ("机械".equals(dataSourceModel.getMajor())) {
                                busCondition.setType(25);
                            }
                            if ("流体".equals(dataSourceModel.getMajor())) {
                                busCondition.setType(26);
                            }
                            if ("自动化".equals(dataSourceModel.getMajor())) {
                                busCondition.setType(27);
                            }
                            busCondition.setLaborTypes("9,11");
                            busCondition.setDataUseType(2);
                            busCondition.setPart(dataSourceModel.getPart());
                            busCondition.setDsId(dataSourceModel.getId());
                            getDataDao.deleteBusGeneralHoursByConditionModel(busCondition);
                            List<CosSheetModel> sprayList = getDataDao.findCosManufactureModelList(condition);
                            for (CosSheetModel sprayCosSheetModel : sprayList) {
                                BusGeneralHours busGeneralHours = new BusGeneralHours();
                                busGeneralHours.setProCode(busBudgetAccountingTask.getProCode());
                                busGeneralHours.setPart(dataSourceModel.getPart());
                                if ("机械".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(25);
                                }
                                if ("流体".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(26);
                                }
                                if ("自动化".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(27);
                                }
                                if ("人工工时喷".equals(sprayCosSheetModel.getDataType())) {
                                    busGeneralHours.setLaborType(9);
                                } else if ("人工工时涂".equals(sprayCosSheetModel.getDataType())) {
                                    busGeneralHours.setLaborType(11);
                                }

                                busGeneralHours.setLaborNum(sprayCosSheetModel.getQuantity());
                                busGeneralHours.setLaborName(sprayCosSheetModel.getDescribe());
                                busGeneralHours.setUnit(sprayCosSheetModel.getUnit());
                                busGeneralHours.setRemark(sprayCosSheetModel.getRemark());
                                busGeneralHours.setBatId(busBudgetAccountingTask.getId());
                                busGeneralHours.setPlaceDelivery(null);
                                busGeneralHours.setDestination(null);
                                //机械工程部平均日工资
                                BigDecimal price = getDataDao.getConfigTemplatePriceByCode("Average daily wage per capita of Zhongwang machinery");
                                busGeneralHours.setPrice(price);
                                busGeneralHours.setDsId(dataSourceModel.getId());
                                busGeneralHours.setPriceType(1);
                                busGeneralHours.setDataUseType(2);
                                busGeneralHours.setMajor(dataSourceModel.getMajor());
                                busGeneralHours.setGetDate(currentDate);
                                busGeneralHours.setAmount(busGeneralHours.getLaborNum().multiply(busGeneralHours.getPrice()));
                                busGeneralHours.setGetUid(ShiroUtils.getUserId());
                                busGeneralHours.setPostDept(sprayCosSheetModel.getBranchName());
                                busGeneralHours.setPostName(sprayCosSheetModel.getCreateName());
                                getDataDao.insertBusGeneralHours(busGeneralHours);
                                sprayCosSheetModel.setReceiveStatus((byte) 1);
                                sprayCosSheetModel.setReceiveTime(currentDate);
                                getDataDao.updateCosSheetModelReceiveInfoByPrimaryKey(sprayCosSheetModel);
                            }

                            //辅材
                            //清空辅材信息
                            BusGeneralHoursModel bghCondition = new BusGeneralHoursModel();
                            bghCondition.setMajor(dataSourceModel.getMajor());
                            if ("机械".equals(dataSourceModel.getMajor())) {
                                bghCondition.setType(25);
                            }
                            if ("流体".equals(dataSourceModel.getMajor())) {
                                bghCondition.setType(26);
                            }
                            if ("自动化".equals(dataSourceModel.getMajor())) {
                                bghCondition.setType(27);
                            }
                            bghCondition.setLaborTypes("10,12");
                            bghCondition.setBatId(busBudgetAccountingTask.getId());
                            bghCondition.setPart(dataSourceModel.getPart());
                            bghCondition.setDataUseType(2);
                            bghCondition.setDsId(dataSourceModel.getId());
                            getDataDao.deleteBusGeneralHoursByConditionModel(bghCondition);
                            //获取辅材数据
                            CosSheetModel auxiliaryMaterialsCondition = new CosSheetModel();
                            auxiliaryMaterialsCondition.setProCode(busBudgetAccountingTask.getProCode());
                            auxiliaryMaterialsCondition.setSpecial(dataSourceModel.getMajor());
                            auxiliaryMaterialsCondition.setCostType((byte) 6);
                            auxiliaryMaterialsCondition.setProPart(dataSourceModel.getPart());
                            auxiliaryMaterialsCondition.setIsDel((byte) 0);
                            auxiliaryMaterialsCondition.setStatus((byte) 3);
                            auxiliaryMaterialsCondition.setDataTypes("'主要辅材涂','主要辅材喷'");
                            List<CosSheetModel> auxiliaryMaterialsList = getDataDao.findCosManufactureModelList(auxiliaryMaterialsCondition);
                            for (CosSheetModel auxiliaryMaterialsCosSheetModel : auxiliaryMaterialsList) {
                                BusGeneralHours busGeneralHours = new BusGeneralHours();
                                busGeneralHours.setProCode(busBudgetAccountingTask.getProCode());
                                busGeneralHours.setPart(dataSourceModel.getPart());
                                if ("机械".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(25);
                                }
                                if ("流体".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(26);
                                }
                                if ("自动化".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(27);
                                }
                                if ("主要辅材涂".equals(auxiliaryMaterialsCosSheetModel.getDataType())) {
                                    busGeneralHours.setLaborType(12);
                                } else if ("主要辅材喷".equals(auxiliaryMaterialsCosSheetModel.getDataType())) {
                                    busGeneralHours.setLaborType(10);
                                }
                                busGeneralHours.setLaborNum(auxiliaryMaterialsCosSheetModel.getQuantity());
                                busGeneralHours.setLaborName(auxiliaryMaterialsCosSheetModel.getDescribe());
                                busGeneralHours.setUnit(auxiliaryMaterialsCosSheetModel.getUnit());
                                busGeneralHours.setRemark(auxiliaryMaterialsCosSheetModel.getRemark());
                                busGeneralHours.setBatId(busBudgetAccountingTask.getId());
                                busGeneralHours.setPlaceDelivery(null);
                                busGeneralHours.setDestination(null);
//                            //机械工程部平均日工资
//                            BigDecimal price = getDataDao.getConfigTemplatePriceByCode("spray");
//                            busGeneralHours.setPrice(price);
                                busGeneralHours.setDsId(dataSourceModel.getId());
                                busGeneralHours.setPriceType(1);
                                busGeneralHours.setDataUseType(2);
                                busGeneralHours.setMajor(dataSourceModel.getMajor());
                                busGeneralHours.setGetDate(currentDate);
                                busGeneralHours.setAmount(null);
                                busGeneralHours.setGetUid(ShiroUtils.getUserId());
                                busGeneralHours.setPostDept(auxiliaryMaterialsCosSheetModel.getBranchName());
                                busGeneralHours.setPostName(auxiliaryMaterialsCosSheetModel.getCreateName());
                                getDataDao.insertBusGeneralHours(busGeneralHours);
                                auxiliaryMaterialsCosSheetModel.setReceiveStatus((byte) 1);
                                auxiliaryMaterialsCosSheetModel.setReceiveTime(currentDate);
                                getDataDao.updateCosSheetModelReceiveInfoByPrimaryKey(auxiliaryMaterialsCosSheetModel);
                            }
                            if (auxiliaryMaterialsList.size() > 0 || sprayList.size() > 0) {
                                if (auxiliaryMaterialsList.size() > 0) {
                                    dataSourceModel.setStaff(auxiliaryMaterialsList.get(0).getCreateName());
                                    dataSourceModel.setDept(auxiliaryMaterialsList.get(0).getBranchName());
                                    dataSourceModel.setAddDate(auxiliaryMaterialsList.get(0).getVerifyTime());
                                } else {
                                    dataSourceModel.setStaff(sprayList.get(0).getCreateName());
                                    dataSourceModel.setDept(sprayList.get(0).getBranchName());
                                    dataSourceModel.setAddDate(sprayList.get(0).getVerifyTime());
                                }
                                dataSourceModel.setReceiveDate(currentDate);
                                dataSourceModel.setReceiveStatus(1);
                                dataSourceModel.setSource(dataSourceText);
                                dataSourceModel.setDataStatus(3);
                                getDataDao.updateDataSourceByPrimaryKeySelectivity(dataSourceModel);
                                dataSource.setDataStatus(3);
                                dataSource.setReceiveStatus(1);
                                dataSource.setReceiveDate(currentDate);
                                dataSource.setSource("生产管理系统");
                                getDataDao.updateDataSourceReceiveInfo(dataSource);
                            }
                        }
                        //获取 装配工时 辅材 两张表数据
                        else if ("ds011".equals(dataSourceModel.getDataCode())) {
                            //实际工时
                            CosSheetModel condition = new CosSheetModel();
                            condition.setProCode(busBudgetAccountingTask.getProCode());
                            condition.setSpecial(dataSourceModel.getMajor());
                            condition.setCostType((byte) 5);
                            condition.setProPart(dataSourceModel.getPart());
                            condition.setIsDel((byte) 0);
                            condition.setStatus((byte) 3);
                            condition.setDataType("人工工时");
                            //根据条件清空数据
                            BusGeneralHoursModel busCondition = new BusGeneralHoursModel();
                            busCondition.setMajor(dataSourceModel.getMajor());
                            busCondition.setBatId(busBudgetAccountingTask.getId());
                            if ("机械".equals(dataSourceModel.getMajor())) {
                                busCondition.setType(31);
                            }
                            if ("流体".equals(dataSourceModel.getMajor())) {
                                busCondition.setType(32);
                            }
                            if ("自动化".equals(dataSourceModel.getMajor())) {
                                busCondition.setType(33);
                            }
                            busCondition.setLaborTypes("13");
                            busCondition.setDataUseType(2);
                            busCondition.setPart(dataSourceModel.getPart());
                            busCondition.setDsId(dataSourceModel.getId());
                            getDataDao.deleteBusGeneralHoursByConditionModel(busCondition);
                            List<CosSheetModel> assemblingList = getDataDao.findCosManufactureModelList(condition);
                            for (CosSheetModel assemblingCosSheetModel : assemblingList) {
                                BusGeneralHours busGeneralHours = new BusGeneralHours();
                                busGeneralHours.setProCode(busBudgetAccountingTask.getProCode());
                                busGeneralHours.setPart(dataSourceModel.getPart());
                                if ("机械".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(31);
                                }
                                if ("流体".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(32);
                                }
                                if ("自动化".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(33);
                                }
                                busGeneralHours.setLaborType(13);
                                busGeneralHours.setLaborNum(assemblingCosSheetModel.getQuantity());
                                busGeneralHours.setLaborName(assemblingCosSheetModel.getDescribe());
                                busGeneralHours.setUnit(assemblingCosSheetModel.getUnit());
                                busGeneralHours.setRemark(assemblingCosSheetModel.getRemark());
                                busGeneralHours.setBatId(busBudgetAccountingTask.getId());
                                busGeneralHours.setPlaceDelivery(null);
                                busGeneralHours.setDestination(null);
                                //装配人均工资
                                BigDecimal price = getDataDao.getConfigTemplatePriceByCode("Average daily wage per capita of Zhongwang machinery");
                                busGeneralHours.setPrice(price);
                                busGeneralHours.setDsId(dataSourceModel.getId());
                                busGeneralHours.setPriceType(1);
                                busGeneralHours.setDataUseType(2);
                                busGeneralHours.setMajor(dataSourceModel.getMajor());
                                busGeneralHours.setGetDate(currentDate);
                                busGeneralHours.setAmount(busGeneralHours.getLaborNum().multiply(busGeneralHours.getPrice()));
                                busGeneralHours.setGetUid(ShiroUtils.getUserId());
                                busGeneralHours.setPostDept(assemblingCosSheetModel.getBranchName());
                                busGeneralHours.setPostName(assemblingCosSheetModel.getCreateName());
                                getDataDao.insertBusGeneralHours(busGeneralHours);
                                assemblingCosSheetModel.setReceiveStatus((byte) 1);
                                assemblingCosSheetModel.setReceiveTime(currentDate);
                                getDataDao.updateCosSheetModelReceiveInfoByPrimaryKey(assemblingCosSheetModel);
                            }

                            //辅材
                            //清空辅材信息
                            BusGeneralHoursModel bghCondition = new BusGeneralHoursModel();
                            bghCondition.setMajor(dataSourceModel.getMajor());
                            if ("机械".equals(dataSourceModel.getMajor())) {
                                bghCondition.setType(31);
                            }
                            if ("流体".equals(dataSourceModel.getMajor())) {
                                bghCondition.setType(32);
                            }
                            if ("自动化".equals(dataSourceModel.getMajor())) {
                                bghCondition.setType(33);
                            }
                            bghCondition.setLaborTypes("14");
                            bghCondition.setBatId(busBudgetAccountingTask.getId());
                            bghCondition.setPart(dataSourceModel.getPart());
                            bghCondition.setDataUseType(2);
                            bghCondition.setDsId(dataSourceModel.getId());
                            getDataDao.deleteBusGeneralHoursByConditionModel(bghCondition);
                            //获取辅材数据
                            CosSheetModel auxiliaryMaterialsCondition = new CosSheetModel();
                            auxiliaryMaterialsCondition.setProCode(busBudgetAccountingTask.getProCode());
                            auxiliaryMaterialsCondition.setSpecial(dataSourceModel.getMajor());
                            auxiliaryMaterialsCondition.setCostType((byte) 5);
                            auxiliaryMaterialsCondition.setProPart(dataSourceModel.getPart());
                            auxiliaryMaterialsCondition.setIsDel((byte) 0);
                            auxiliaryMaterialsCondition.setStatus((byte) 3);
                            auxiliaryMaterialsCondition.setDataTypes("'主要辅材'");
                            List<CosSheetModel> auxiliaryMaterialsList = getDataDao.findCosManufactureModelList(auxiliaryMaterialsCondition);
                            for (CosSheetModel auxiliaryMaterialsCosSheetModel : auxiliaryMaterialsList) {
                                BusGeneralHours busGeneralHours = new BusGeneralHours();
                                busGeneralHours.setProCode(busBudgetAccountingTask.getProCode());
                                busGeneralHours.setPart(dataSourceModel.getPart());
                                if ("机械".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(31);
                                }
                                if ("流体".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(32);
                                }
                                if ("自动化".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(33);
                                }
                                busGeneralHours.setLaborType(14);
                                busGeneralHours.setLaborNum(auxiliaryMaterialsCosSheetModel.getQuantity());
                                busGeneralHours.setLaborName(auxiliaryMaterialsCosSheetModel.getDescribe());
                                busGeneralHours.setUnit(auxiliaryMaterialsCosSheetModel.getUnit());
                                busGeneralHours.setRemark(auxiliaryMaterialsCosSheetModel.getRemark());
                                busGeneralHours.setBatId(busBudgetAccountingTask.getId());
                                busGeneralHours.setPlaceDelivery(null);
                                busGeneralHours.setDestination(null);
//                            //机械工程部平均日工资
//                            BigDecimal price = getDataDao.getConfigTemplatePriceByCode("Average daily wage per capita of Zhongwang machinery");
//                            busGeneralHours.setPrice(price);
                                busGeneralHours.setDsId(dataSourceModel.getId());
                                busGeneralHours.setPriceType(1);
                                busGeneralHours.setDataUseType(2);
                                busGeneralHours.setMajor(dataSourceModel.getMajor());
                                busGeneralHours.setGetDate(currentDate);
                                busGeneralHours.setAmount(null);
                                busGeneralHours.setGetUid(ShiroUtils.getUserId());
                                busGeneralHours.setPostDept(auxiliaryMaterialsCosSheetModel.getBranchName());
                                busGeneralHours.setPostName(auxiliaryMaterialsCosSheetModel.getCreateName());
                                getDataDao.insertBusGeneralHours(busGeneralHours);
                                auxiliaryMaterialsCosSheetModel.setReceiveStatus((byte) 1);
                                auxiliaryMaterialsCosSheetModel.setReceiveTime(currentDate);
                                getDataDao.updateCosSheetModelReceiveInfoByPrimaryKey(auxiliaryMaterialsCosSheetModel);
                            }
                            if (auxiliaryMaterialsList.size() > 0 || assemblingList.size() > 0) {
                                if (auxiliaryMaterialsList.size() > 0) {
                                    dataSourceModel.setStaff(auxiliaryMaterialsList.get(0).getCreateName());
                                    dataSourceModel.setDept(auxiliaryMaterialsList.get(0).getBranchName());
                                    dataSourceModel.setAddDate(auxiliaryMaterialsList.get(0).getVerifyTime());
                                } else {
                                    dataSourceModel.setStaff(assemblingList.get(0).getCreateName());
                                    dataSourceModel.setDept(assemblingList.get(0).getBranchName());
                                    dataSourceModel.setAddDate(assemblingList.get(0).getVerifyTime());
                                }
                                dataSourceModel.setReceiveDate(currentDate);
                                dataSourceModel.setReceiveStatus(1);
                                dataSourceModel.setSource(dataSourceText);
                                dataSourceModel.setDataStatus(3);
                                getDataDao.updateDataSourceByPrimaryKeySelectivity(dataSourceModel);
                                dataSource.setDataStatus(3);
                                dataSource.setReceiveStatus(1);
                                dataSource.setReceiveDate(currentDate);
                                dataSource.setSource("生产管理系统");
                                getDataDao.updateDataSourceReceiveInfo(dataSource);
                            }
                        }
                        //获取 运输费表 包装工时表  辅材表三张表信息
                        else if ("ds012".equals(dataSourceModel.getDataCode())) {
                            //清空运输费表
                            BusGeneralHoursModel transportCondition = new BusGeneralHoursModel();
                            transportCondition.setProCode(busBudgetAccountingTask.getProCode());
                            transportCondition.setPart(dataSourceModel.getPart());
                            transportCondition.setType(34);
                            transportCondition.setMajor(dataSourceModel.getMajor());
                            transportCondition.setLaborType(17);
                            transportCondition.setBatId(busBudgetAccountingTask.getId());
                            transportCondition.setDsId(dataSourceModel.getId());
                            transportCondition.setDataUseType(2);
                            getDataDao.deleteBusGeneralHoursByConditionModel(transportCondition);
                            //获取运输费信息
                            CosSheetModel condition = new CosSheetModel();
                            condition.setProCode(busBudgetAccountingTask.getProCode());
                            condition.setSpecial(dataSourceModel.getMajor());
                            condition.setCostType((byte) 9);
                            condition.setProPart(dataSourceModel.getPart());
                            condition.setIsDel((byte) 0);
                            condition.setStatus((byte) 3);
                            List<CosSheetModel> cosTransportInfoModelList = getDataDao.findFreightList(condition);
                            for (CosSheetModel data : cosTransportInfoModelList) {
                                BusGeneralHours busGeneralHours = new BusGeneralHours();
                                busGeneralHours.setProCode(busBudgetAccountingTask.getProCode());
                                busGeneralHours.setPart(dataSourceModel.getPart());
                                busGeneralHours.setType(34);
                                busGeneralHours.setMajor(dataSourceModel.getMajor());
                                busGeneralHours.setLaborType(17);
                                busGeneralHours.setLaborName("运费");
                                busGeneralHours.setLaborNum(data.getWeight());
                                busGeneralHours.setUnit(data.getUnit());
                                busGeneralHours.setRemark(data.getRemark());
                                busGeneralHours.setBatId(busBudgetAccountingTask.getId());
                                busGeneralHours.setPlaceDelivery(data.getOrigin());
                                busGeneralHours.setDestination(data.getDestination());
                                busGeneralHours.setCarNum(data.getVehicle().intValue());
                                busGeneralHours.setDistance(data.getDistance());
                                busGeneralHours.setDistanceUnit(data.getUnit());
                                busGeneralHours.setPrice(data.getCarriage());
                                busGeneralHours.setPriceType(1);
                                busGeneralHours.setDsId(dataSourceModel.getId());
                                busGeneralHours.setGetDate(currentDate);
                                busGeneralHours.setGetUid(ShiroUtils.getUserId());
                                busGeneralHours.setDataUseType(2);
                                busGeneralHours.setPostDept(data.getBranchName());
                                busGeneralHours.setPostName(data.getCreateName());
                                getDataDao.insertBusGeneralHours(busGeneralHours);
                                data.setReceiveStatus((byte) 1);
                                data.setReceiveTime(currentDate);
                                getDataDao.updateCosSheetModelReceiveInfoByPrimaryKey(data);
                            }

                            //实际工时
                            CosSheetModel workHoursCondition = new CosSheetModel();
                            workHoursCondition.setProCode(busBudgetAccountingTask.getProCode());
                            workHoursCondition.setSpecial(dataSourceModel.getMajor());
                            workHoursCondition.setCostType((byte) 9);
                            workHoursCondition.setProPart(dataSourceModel.getPart());
                            workHoursCondition.setIsDel((byte) 0);
                            workHoursCondition.setStatus((byte) 3);
                            workHoursCondition.setDataType("人工工时");
                            //根据条件清空数据
                            BusGeneralHoursModel busCondition = new BusGeneralHoursModel();
                            busCondition.setMajor(dataSourceModel.getMajor());
                            busCondition.setBatId(busBudgetAccountingTask.getId());
                            busCondition.setType(34);
                            busCondition.setLaborTypes("15");
                            busCondition.setDataUseType(2);
                            busCondition.setPart(dataSourceModel.getPart());
                            busCondition.setDsId(dataSourceModel.getId());
                            getDataDao.deleteBusGeneralHoursByConditionModel(busCondition);
                            List<CosSheetModel> packingList = getDataDao.findCosManufactureModelList(workHoursCondition);
                            for (CosSheetModel packingCosSheetModel : packingList) {
                                BusGeneralHours busGeneralHours = new BusGeneralHours();
                                busGeneralHours.setProCode(busBudgetAccountingTask.getProCode());
                                busGeneralHours.setPart(dataSourceModel.getPart());
                                busGeneralHours.setType(34);
                                busGeneralHours.setLaborType(15);
                                busGeneralHours.setLaborNum(packingCosSheetModel.getQuantity());
                                busGeneralHours.setLaborName(packingCosSheetModel.getDescribe());
                                busGeneralHours.setUnit(packingCosSheetModel.getUnit());
                                busGeneralHours.setRemark(packingCosSheetModel.getRemark());
                                busGeneralHours.setBatId(busBudgetAccountingTask.getId());
                                busGeneralHours.setPlaceDelivery(null);
                                busGeneralHours.setDestination(null);
                                //平均日工资
                                BigDecimal price = getDataDao.getConfigTemplatePriceByCode("Average daily wage per capita of Zhongwang machinery");
                                busGeneralHours.setPrice(price);
                                busGeneralHours.setDsId(dataSourceModel.getId());
                                busGeneralHours.setPriceType(1);
                                busGeneralHours.setDataUseType(2);
                                busGeneralHours.setMajor(dataSourceModel.getMajor());
                                busGeneralHours.setGetDate(currentDate);
                                busGeneralHours.setAmount(busGeneralHours.getLaborNum().multiply(busGeneralHours.getPrice()));
                                busGeneralHours.setGetUid(ShiroUtils.getUserId());
                                busGeneralHours.setPostDept(packingCosSheetModel.getBranchName());
                                busGeneralHours.setPostName(packingCosSheetModel.getCreateName());
                                getDataDao.insertBusGeneralHours(busGeneralHours);
                                packingCosSheetModel.setReceiveStatus((byte) 1);
                                packingCosSheetModel.setReceiveTime(currentDate);
                                getDataDao.updateCosSheetModelReceiveInfoByPrimaryKey(packingCosSheetModel);
                            }

                            //辅材
                            //清空辅材信息
                            BusGeneralHoursModel bghCondition = new BusGeneralHoursModel();

                            bghCondition.setType(34);
                            bghCondition.setLaborTypes("16");
                            bghCondition.setBatId(busBudgetAccountingTask.getId());
                            bghCondition.setPart(dataSourceModel.getPart());
                            bghCondition.setDataUseType(2);
                            bghCondition.setDsId(dataSourceModel.getId());
                            bghCondition.setMajor(dataSourceModel.getMajor());
                            getDataDao.deleteBusGeneralHoursByConditionModel(bghCondition);
                            //获取辅材数据
                            CosSheetModel auxiliaryMaterialsCondition = new CosSheetModel();
                            auxiliaryMaterialsCondition.setProCode(busBudgetAccountingTask.getProCode());
                            auxiliaryMaterialsCondition.setSpecial(dataSourceModel.getMajor());
                            auxiliaryMaterialsCondition.setCostType((byte) 9);
                            auxiliaryMaterialsCondition.setProPart(dataSourceModel.getPart());
                            auxiliaryMaterialsCondition.setIsDel((byte) 0);
                            auxiliaryMaterialsCondition.setStatus((byte) 3);
                            auxiliaryMaterialsCondition.setDataType("主要辅材");
                            List<CosSheetModel> auxiliaryMaterialsList = getDataDao.findCosManufactureModelList(auxiliaryMaterialsCondition);
                            for (CosSheetModel auxiliaryMaterialsCosSheetModel : auxiliaryMaterialsList) {
                                BusGeneralHours busGeneralHours = new BusGeneralHours();
                                busGeneralHours.setProCode(busBudgetAccountingTask.getProCode());
                                busGeneralHours.setPart(dataSourceModel.getPart());
                                busGeneralHours.setType(34);
                                busGeneralHours.setLaborType(16);
                                busGeneralHours.setLaborNum(auxiliaryMaterialsCosSheetModel.getQuantity());
                                busGeneralHours.setLaborName(auxiliaryMaterialsCosSheetModel.getDescribe());
                                busGeneralHours.setUnit(auxiliaryMaterialsCosSheetModel.getUnit());
                                busGeneralHours.setRemark(auxiliaryMaterialsCosSheetModel.getRemark());
                                busGeneralHours.setBatId(busBudgetAccountingTask.getId());
                                busGeneralHours.setPlaceDelivery(null);
                                busGeneralHours.setDestination(null);
                                busGeneralHours.setPrice(null);
                                busGeneralHours.setDsId(dataSourceModel.getId());
                                busGeneralHours.setPriceType(1);
                                busGeneralHours.setDataUseType(2);
                                busGeneralHours.setMajor(dataSourceModel.getMajor());
                                busGeneralHours.setGetDate(currentDate);
                                busGeneralHours.setPrice(null);
                                busGeneralHours.setAmount(null);
                                busGeneralHours.setGetUid(ShiroUtils.getUserId());
                                busGeneralHours.setPostDept(auxiliaryMaterialsCosSheetModel.getBranchName());
                                busGeneralHours.setPostName(auxiliaryMaterialsCosSheetModel.getCreateName());
                                getDataDao.insertBusGeneralHours(busGeneralHours);
                                auxiliaryMaterialsCosSheetModel.setReceiveStatus((byte) 1);
                                auxiliaryMaterialsCosSheetModel.setReceiveTime(currentDate);
                                getDataDao.updateCosSheetModelReceiveInfoByPrimaryKey(auxiliaryMaterialsCosSheetModel);
                            }
                            if (auxiliaryMaterialsList.size() > 0 || packingList.size() > 0) {
                                if (auxiliaryMaterialsList.size() > 0) {
                                    dataSourceModel.setStaff(auxiliaryMaterialsList.get(0).getCreateName());
                                    dataSourceModel.setDept(auxiliaryMaterialsList.get(0).getBranchName());
                                    dataSourceModel.setAddDate(auxiliaryMaterialsList.get(0).getVerifyTime());
                                } else {
                                    dataSourceModel.setStaff(packingList.get(0).getCreateName());
                                    dataSourceModel.setDept(packingList.get(0).getBranchName());
                                    dataSourceModel.setAddDate(packingList.get(0).getVerifyTime());
                                }
                                dataSourceModel.setReceiveDate(currentDate);
                                dataSourceModel.setReceiveStatus(1);
                                dataSourceModel.setSource(dataSourceText);
                                dataSourceModel.setDataStatus(3);
                                getDataDao.updateDataSourceByPrimaryKeySelectivity(dataSourceModel);
                                dataSource.setDataStatus(3);
                                dataSource.setReceiveStatus(1);
                                dataSource.setReceiveDate(currentDate);
                                dataSource.setSource("生产管理系统");
                                getDataDao.updateDataSourceReceiveInfo(dataSource);
                            }
                        }
                        //获取 安装工时表  辅材表两张表信息
                        else if ("ds013".equals(dataSourceModel.getDataCode())) {

                            //根据条件清空数据
                            BusGeneralHoursModel busCondition = new BusGeneralHoursModel();
                            busCondition.setMajor(dataSourceModel.getMajor());
                            busCondition.setBatId(busBudgetAccountingTask.getId());
                            if ("机械".equals(dataSourceModel.getMajor())) {
                                busCondition.setType(38);
                            }
                            if ("流体".equals(dataSourceModel.getMajor())) {
                                busCondition.setType(39);
                            }
                            if ("自动化".equals(dataSourceModel.getMajor())) {
                                busCondition.setType(40);
                            }
                            busCondition.setLaborTypes("18");
                            busCondition.setDataUseType(2);
                            busCondition.setPart(dataSourceModel.getPart());
                            busCondition.setDsId(dataSourceModel.getId());
                            getDataDao.deleteBusGeneralHoursByConditionModel(busCondition);
                            //实际工时
                            CosSheetModel workHoursCondition = new CosSheetModel();
                            workHoursCondition.setProCode(busBudgetAccountingTask.getProCode());
                            workHoursCondition.setSpecial(dataSourceModel.getMajor());
                            workHoursCondition.setCostType((byte) 7);
                            workHoursCondition.setProPart(dataSourceModel.getPart());
                            workHoursCondition.setIsDel((byte) 0);
                            workHoursCondition.setStatus((byte) 3);
                            workHoursCondition.setDataType("人工工时");
                            List<CosSheetModel> installList = getDataDao.findCosManufactureModelList(workHoursCondition);
                            for (CosSheetModel installCosSheetModel : installList) {
                                BusGeneralHours busGeneralHours = new BusGeneralHours();
                                busGeneralHours.setProCode(busBudgetAccountingTask.getProCode());
                                busGeneralHours.setPart(dataSourceModel.getPart());
                                if ("机械".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(38);
                                }
                                if ("流体".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(39);
                                }
                                if ("自动化".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(40);
                                }
                                busGeneralHours.setLaborType(18);
                                busGeneralHours.setLaborNum(installCosSheetModel.getQuantity());
                                busGeneralHours.setLaborName(installCosSheetModel.getDescribe());
                                busGeneralHours.setUnit(installCosSheetModel.getUnit());
                                busGeneralHours.setRemark(installCosSheetModel.getRemark());
                                busGeneralHours.setBatId(busBudgetAccountingTask.getId());
                                busGeneralHours.setPlaceDelivery(null);
                                busGeneralHours.setDestination(null);
                                //装配人均工资
                                BigDecimal price = getDataDao.getConfigTemplatePriceByCode("Per capita wage of site installation");
                                busGeneralHours.setPrice(price);
                                busGeneralHours.setDsId(dataSourceModel.getId());
                                busGeneralHours.setPriceType(1);
                                busGeneralHours.setDataUseType(2);
                                busGeneralHours.setMajor(dataSourceModel.getMajor());
                                busGeneralHours.setGetDate(currentDate);
                                busGeneralHours.setAmount(busGeneralHours.getLaborNum().multiply(busGeneralHours.getPrice()));
                                busGeneralHours.setGetUid(ShiroUtils.getUserId());
                                busGeneralHours.setPostDept(installCosSheetModel.getBranchName());
                                busGeneralHours.setPostName(installCosSheetModel.getCreateName());
                                getDataDao.insertBusGeneralHours(busGeneralHours);
                                installCosSheetModel.setReceiveStatus((byte) 1);
                                installCosSheetModel.setReceiveTime(currentDate);
                                getDataDao.updateCosSheetModelReceiveInfoByPrimaryKey(installCosSheetModel);
                            }

                            //辅材
                            //清空辅材信息
                            BusGeneralHoursModel bghCondition = new BusGeneralHoursModel();
                            bghCondition.setMajor(dataSourceModel.getMajor());
                            if ("机械".equals(dataSourceModel.getMajor())) {
                                bghCondition.setType(38);
                            }
                            if ("流体".equals(dataSourceModel.getMajor())) {
                                bghCondition.setType(39);
                            }
                            if ("自动化".equals(dataSourceModel.getMajor())) {
                                bghCondition.setType(40);
                            }
                            bghCondition.setLaborTypes("19");
                            bghCondition.setBatId(busBudgetAccountingTask.getId());
                            bghCondition.setPart(dataSourceModel.getPart());
                            bghCondition.setDataUseType(2);
                            bghCondition.setDsId(dataSourceModel.getId());
                            getDataDao.deleteBusGeneralHoursByConditionModel(bghCondition);
                            //获取辅材数据
                            CosSheetModel auxiliaryMaterialsCondition = new CosSheetModel();
                            auxiliaryMaterialsCondition.setProCode(busBudgetAccountingTask.getProCode());
                            auxiliaryMaterialsCondition.setSpecial(dataSourceModel.getMajor());
                            auxiliaryMaterialsCondition.setCostType((byte) 7);
                            auxiliaryMaterialsCondition.setProPart(dataSourceModel.getPart());
                            auxiliaryMaterialsCondition.setIsDel((byte) 0);
                            auxiliaryMaterialsCondition.setStatus((byte) 3);
                            auxiliaryMaterialsCondition.setDataType("主要辅材");
                            List<CosSheetModel> auxiliaryMaterialsList = getDataDao.findCosManufactureModelList(auxiliaryMaterialsCondition);
                            for (CosSheetModel auxiliaryMaterialsCosSheetModel : auxiliaryMaterialsList) {
                                BusGeneralHours busGeneralHours = new BusGeneralHours();
                                busGeneralHours.setProCode(busBudgetAccountingTask.getProCode());
                                busGeneralHours.setPart(dataSourceModel.getPart());
                                if ("机械".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(38);
                                }
                                if ("流体".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(39);
                                }
                                if ("自动化".equals(dataSourceModel.getMajor())) {
                                    busGeneralHours.setType(40);
                                }
                                busGeneralHours.setLaborType(19);
                                busGeneralHours.setLaborNum(auxiliaryMaterialsCosSheetModel.getQuantity());
                                busGeneralHours.setLaborName(auxiliaryMaterialsCosSheetModel.getDescribe());
                                busGeneralHours.setUnit(auxiliaryMaterialsCosSheetModel.getUnit());
                                busGeneralHours.setRemark(auxiliaryMaterialsCosSheetModel.getRemark());
                                busGeneralHours.setBatId(busBudgetAccountingTask.getId());
                                busGeneralHours.setPlaceDelivery(null);
                                busGeneralHours.setDestination(null);
                                busGeneralHours.setPrice(null);
                                busGeneralHours.setDsId(dataSourceModel.getId());
                                busGeneralHours.setPriceType(1);
                                busGeneralHours.setDataUseType(2);
                                busGeneralHours.setMajor(dataSourceModel.getMajor());
                                busGeneralHours.setGetDate(currentDate);
                                busGeneralHours.setAmount(null);
                                busGeneralHours.setGetUid(ShiroUtils.getUserId());
                                busGeneralHours.setPostDept(auxiliaryMaterialsCosSheetModel.getBranchName());
                                busGeneralHours.setPostName(auxiliaryMaterialsCosSheetModel.getCreateName());
                                getDataDao.insertBusGeneralHours(busGeneralHours);
                                auxiliaryMaterialsCosSheetModel.setReceiveStatus((byte) 1);
                                auxiliaryMaterialsCosSheetModel.setReceiveTime(currentDate);
                                getDataDao.updateCosSheetModelReceiveInfoByPrimaryKey(auxiliaryMaterialsCosSheetModel);
                            }
                            if (auxiliaryMaterialsList.size() > 0 || installList.size() > 0) {
                                if (auxiliaryMaterialsList.size() > 0) {
                                    dataSourceModel.setStaff(auxiliaryMaterialsList.get(0).getCreateName());
                                    dataSourceModel.setDept(auxiliaryMaterialsList.get(0).getBranchName());
                                    dataSourceModel.setAddDate(auxiliaryMaterialsList.get(0).getVerifyTime());
                                } else {
                                    dataSourceModel.setStaff(installList.get(0).getCreateName());
                                    dataSourceModel.setDept(installList.get(0).getBranchName());
                                    dataSourceModel.setAddDate(installList.get(0).getVerifyTime());
                                }
                                dataSourceModel.setReceiveDate(currentDate);
                                dataSourceModel.setReceiveStatus(1);
                                dataSourceModel.setSource(dataSourceText);
                                dataSourceModel.setDataStatus(3);
                                getDataDao.updateDataSourceByPrimaryKeySelectivity(dataSourceModel);
                                dataSource.setDataStatus(3);
                                dataSource.setReceiveStatus(1);
                                dataSource.setReceiveDate(currentDate);
                                dataSource.setSource("生产管理系统");
                                getDataDao.updateDataSourceReceiveInfo(dataSource);
                            }
                        }
                    }
                }
            }
            //获取需要反写数据源信息的成本项
            BusBudgetAccountingCostModel condition = new BusBudgetAccountingCostModel();
            condition.setBatId(busBudgetAccountingTask.getId());
            condition.setShowDataSource(1);
            List<BusBudgetAccountingCostModel> costList = getDataDao.findBusBudgetAccountingCostByCondition(condition);
            //开始检测成本项相关的数据
            for (BusBudgetAccountingCostModel cost : costList) {
                if (cost.getCode().contains("-材料费-材料采购费-碳钢") && !"备品备件".equals(cost.getMajor()) && !"随机备件".equals(cost.getMajor())) {
                    BusMaterialDataModel carbonSteelCondition = new BusMaterialDataModel();
                    carbonSteelCondition.setTexture("碳钢");
                    carbonSteelCondition.setDataTypes("1");
                    carbonSteelCondition.setPart(cost.getPart());
                    carbonSteelCondition.setMajor(cost.getMajor());
                    carbonSteelCondition.setDataUseType(2);
                    carbonSteelCondition.setBatId(cost.getBatId());
                    Integer dataCount = getDataDao.getBusMaterialDataDataCountByCondition(carbonSteelCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                } else if (cost.getCode().contains("-材料费-材料采购费-不锈钢") && !"备品备件".equals(cost.getMajor()) && !"随机备件".equals(cost.getMajor())) {
                    BusMaterialDataModel stainlessSteelCondition = new BusMaterialDataModel();
                    stainlessSteelCondition.setTexture("不锈钢");
                    stainlessSteelCondition.setDataTypes("1");
                    stainlessSteelCondition.setPart(cost.getPart());
                    stainlessSteelCondition.setMajor(cost.getMajor());
                    stainlessSteelCondition.setDataUseType(2);
                    stainlessSteelCondition.setBatId(cost.getBatId());
                    Integer dataCount = getDataDao.getBusMaterialDataDataCountByCondition(stainlessSteelCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                } else if (cost.getCode().contains("-材料费-材料采购费-其他") && !"备品备件".equals(cost.getMajor()) && !"随机备件".equals(cost.getMajor())) {
                    BusMaterialDataModel otherCondition = new BusMaterialDataModel();
                    otherCondition.setTexture("其他");
                    otherCondition.setDataTypes("1");
                    otherCondition.setPart(cost.getPart());
                    otherCondition.setMajor(cost.getMajor());
                    otherCondition.setDataUseType(2);
                    otherCondition.setBatId(cost.getBatId());
                    Integer dataCount = getDataDao.getBusMaterialDataDataCountByCondition(otherCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                } else if (cost.getCode().contains("-制造费-下料")) {
                    BusGeneralHoursModel cutCondition = new BusGeneralHoursModel();
                    cutCondition.setBatId(cost.getBatId());
                    cutCondition.setPart(cost.getPart());
                    cutCondition.setMajor(cost.getMajor());
                    cutCondition.setDataUseType(2);
                    switch (cost.getMajor()) {
                        case "机械":
                            cutCondition.setTypes("7");
                            cutCondition.setLaborTypes("4,5");
                            break;
                        case "流体":
                            cutCondition.setTypes("8");
                            cutCondition.setLaborTypes("4,5");
                            break;
                        case "自动化":
                            cutCondition.setTypes("9");
                            cutCondition.setLaborTypes("4,5");
                            break;
                    }
                    Integer dataCount = getDataDao.getBusGeneralHoursCountByCondition(cutCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                } else if (cost.getCode().contains("-制造费-铆焊")) {
                    BusGeneralHoursModel rivetAnSolderCondition = new BusGeneralHoursModel();
                    rivetAnSolderCondition.setBatId(cost.getBatId());
                    rivetAnSolderCondition.setPart(cost.getPart());
                    rivetAnSolderCondition.setMajor(cost.getMajor());
                    rivetAnSolderCondition.setDataUseType(2);
                    switch (cost.getMajor()) {
                        case "机械":
                            rivetAnSolderCondition.setTypes("13");
                            rivetAnSolderCondition.setLaborTypes("6,7");
                            break;
                        case "流体":
                            rivetAnSolderCondition.setTypes("14");
                            rivetAnSolderCondition.setLaborTypes("6,7");
                            break;
                        case "自动化":
                            rivetAnSolderCondition.setTypes("15");
                            rivetAnSolderCondition.setLaborTypes("6,7");
                            break;
                    }
                    Integer dataCount = getDataDao.getBusGeneralHoursCountByCondition(rivetAnSolderCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                } else if (cost.getCode().contains("-制造费-机加")) {
                    BusMachiningHoursModel macCondition = new BusMachiningHoursModel();
                    macCondition.setBatId(cost.getBatId());
                    macCondition.setPart(cost.getPart());
                    macCondition.setMajor(cost.getMajor());
                    macCondition.setDataUseType(2);
                    Integer dataCount = getDataDao.getBusMachiningHoursCountByCondition(macCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                } else if (cost.getCode().contains("-制造费-喷涂")) {
                    BusGeneralHoursModel sprayCondition = new BusGeneralHoursModel();
                    sprayCondition.setBatId(cost.getBatId());
                    sprayCondition.setPart(cost.getPart());
                    sprayCondition.setMajor(cost.getMajor());
                    sprayCondition.setDataUseType(2);
                    switch (cost.getMajor()) {
                        case "机械":
                            sprayCondition.setTypes("25");
                            sprayCondition.setLaborTypes("9,10,11,12");
                            break;
                        case "流体":
                            sprayCondition.setTypes("26");
                            sprayCondition.setLaborTypes("9,10,11,12");
                            break;
                        case "自动化":
                            sprayCondition.setTypes("27");
                            sprayCondition.setLaborTypes("9,10,11,12");
                            break;
                    }
                    Integer dataCount = getDataDao.getBusGeneralHoursCountByCondition(sprayCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                } else if (cost.getCode().contains("-制造费-装配")) {
                    BusGeneralHoursModel assemblingCondition = new BusGeneralHoursModel();
                    assemblingCondition.setBatId(cost.getBatId());
                    assemblingCondition.setPart(cost.getPart());
                    assemblingCondition.setMajor(cost.getMajor());
                    assemblingCondition.setDataUseType(2);
                    switch (cost.getMajor()) {
                        case "机械":
                            assemblingCondition.setTypes("31");
                            assemblingCondition.setLaborTypes("13,14");
                            break;
                        case "流体":
                            assemblingCondition.setTypes("32");
                            assemblingCondition.setLaborTypes("13,14");
                            break;
                        case "自动化":
                            assemblingCondition.setTypes("33");
                            assemblingCondition.setLaborTypes("13,14");
                            break;
                    }
                    Integer dataCount = getDataDao.getBusGeneralHoursCountByCondition(assemblingCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                } else if (cost.getCode().contains("-制造费-热处理")) {
                    BusGeneralHoursModel assemblingCondition = new BusGeneralHoursModel();
                    assemblingCondition.setBatId(cost.getBatId());
                    assemblingCondition.setPart(cost.getPart());
                    assemblingCondition.setMajor(cost.getMajor());
                    assemblingCondition.setDataUseType(2);
                    switch (cost.getMajor()) {
                        case "机械":
                            assemblingCondition.setTypes("19");
                            assemblingCondition.setLaborTypes("8");
                            break;
                        case "流体":
                            assemblingCondition.setTypes("20");
                            assemblingCondition.setLaborTypes("8");
                            break;
                        case "自动化":
                            assemblingCondition.setTypes("21");
                            assemblingCondition.setLaborTypes("8");
                            break;
                    }
                    Integer dataCount = getDataDao.getBusGeneralHoursCountByCondition(assemblingCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                } else if (cost.getCode().contains("-外购费") && !"备品备件".equals(cost.getMajor()) && !"随机备件".equals(cost.getMajor())) {
                    BusMaterialDataModel outsourcingCondition = new BusMaterialDataModel();
                    outsourcingCondition.setDataTypes("2");
                    outsourcingCondition.setPart(cost.getPart());
                    outsourcingCondition.setMajor(cost.getMajor());
                    outsourcingCondition.setDataUseType(2);
                    outsourcingCondition.setBatId(cost.getBatId());
                    Integer dataCount = getDataDao.getBusMaterialDataDataCountByCondition(outsourcingCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                } else if (cost.getCode().contains("-外协费-整体外协") && !"备品备件".equals(cost.getMajor()) && !"随机备件".equals(cost.getMajor())) {
                    BusMaterialDataModel overallCondition = new BusMaterialDataModel();
                    overallCondition.setDataTypes("3,5,6");
                    overallCondition.setPart(cost.getPart());
                    overallCondition.setMajor(cost.getMajor());
                    overallCondition.setDataUseType(2);
                    overallCondition.setBatId(cost.getBatId());
                    Integer dataCount = getDataDao.getBusMaterialDataDataCountByCondition(overallCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                } else if (cost.getCode().contains("-外协费-带料外协") && !"备品备件".equals(cost.getMajor()) && !"随机备件".equals(cost.getMajor())) {
                    BusMaterialDataModel withMatCondition = new BusMaterialDataModel();
                    withMatCondition.setDataTypes("4");
                    withMatCondition.setPart(cost.getPart());
                    withMatCondition.setMajor(cost.getMajor());
                    withMatCondition.setDataUseType(2);
                    withMatCondition.setBatId(cost.getBatId());
                    Integer dataCount = getDataDao.getBusMaterialDataDataCountByCondition(withMatCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                } else if (cost.getCode().contains("-现场安装费-人工-安装人工")) {
                    BusGeneralHoursModel installCondition = new BusGeneralHoursModel();
                    installCondition.setBatId(cost.getBatId());
                    installCondition.setPart(cost.getPart());
                    installCondition.setMajor(cost.getMajor());
                    installCondition.setDataUseType(2);
                    switch (cost.getMajor()) {
                        case "机械":
                            installCondition.setTypes("38");
                            installCondition.setLaborTypes("18");
                            break;
                        case "流体":
                            installCondition.setTypes("39");
                            installCondition.setLaborTypes("18");
                            break;
                        case "自动化":
                            installCondition.setTypes("40");
                            installCondition.setLaborTypes("18");
                            break;
                    }
                    Integer dataCount = getDataDao.getBusGeneralHoursCountByCondition(installCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                } else if (cost.getCode().contains("-现场安装费-人工-调试人工")) {
                    BusGeneralHoursModel debugCondition = new BusGeneralHoursModel();
                    debugCondition.setBatId(cost.getBatId());
                    debugCondition.setPart(cost.getPart());
                    debugCondition.setMajor(cost.getMajor());
                    debugCondition.setDataUseType(2);
                    switch (cost.getMajor()) {
                        case "机械":
                            debugCondition.setTypes("1");
                            debugCondition.setLaborTypes("20");
                            break;
                        case "流体":
                            debugCondition.setTypes("2");
                            debugCondition.setLaborTypes("20");
                            break;
                        case "自动化":
                            debugCondition.setTypes("3");
                            debugCondition.setLaborTypes("20");
                            break;
                    }
                    Integer dataCount = getDataDao.getBusGeneralHoursCountByCondition(debugCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                } else if (cost.getCode().contains("-现场安装费-人工-辅材")) {
                    BusGeneralHoursModel auxiliaryMatCondition = new BusGeneralHoursModel();
                    auxiliaryMatCondition.setBatId(cost.getBatId());
                    auxiliaryMatCondition.setPart(cost.getPart());
                    auxiliaryMatCondition.setMajor(cost.getMajor());
                    auxiliaryMatCondition.setDataUseType(2);
                    switch (cost.getMajor()) {
                        case "机械":
                            auxiliaryMatCondition.setTypes("38");
                            auxiliaryMatCondition.setLaborTypes("19");
                            break;
                        case "流体":
                            auxiliaryMatCondition.setTypes("39");
                            auxiliaryMatCondition.setLaborTypes("19");
                            break;
                        case "自动化":
                            auxiliaryMatCondition.setTypes("40");
                            auxiliaryMatCondition.setLaborTypes("29");
                            break;
                    }
                    Integer dataCount = getDataDao.getBusGeneralHoursCountByCondition(auxiliaryMatCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                } else if (cost.getCode().contains("-设计费")) {
                    BusGeneralHoursModel designMatCondition = new BusGeneralHoursModel();
                    designMatCondition.setBatId(cost.getBatId());
                    designMatCondition.setPart(cost.getPart());
                    designMatCondition.setMajor(cost.getMajor());
                    designMatCondition.setDataUseType(2);
                    switch (cost.getMajor()) {
                        case "机械":
                            designMatCondition.setTypes("1");
                            designMatCondition.setLaborTypes("1");
                            break;
                        case "流体":
                            designMatCondition.setTypes("2");
                            designMatCondition.setLaborTypes("1");
                            break;
                        case "自动化":
                            designMatCondition.setTypes("3");
                            designMatCondition.setLaborTypes("1");
                            break;
                        default:
                            break;
                    }
                    Integer dataCount = getDataDao.getBusGeneralHoursCountByCondition(designMatCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                } else if (cost.getCode().contains("备品备件") || cost.getCode().contains("随机备件")) {
                    BusMaterialDataModel overallCondition = new BusMaterialDataModel();
                    overallCondition.setDataTypes("1,2,3.4,5,6");
                    overallCondition.setPart(cost.getPart());
                    overallCondition.setDataUseType(2);
                    overallCondition.setBatId(cost.getBatId());
                    Integer dataCount = getDataDao.getBusMaterialDataDataCountByCondition(overallCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                } else if (cost.getCode().contains("-包装费")) {
                    BusGeneralHoursModel designMatCondition = new BusGeneralHoursModel();
                    designMatCondition.setBatId(cost.getBatId());
                    designMatCondition.setPart(cost.getPart());
                    designMatCondition.setMajor(cost.getMajor());
                    designMatCondition.setDataUseType(2);
                    designMatCondition.setTypes("34");
                    designMatCondition.setLaborTypes("15,16");
                    Integer dataCount = getDataDao.getBusGeneralHoursCountByCondition(designMatCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                } else if (cost.getCode().contains("-运输费")) {
                    BusGeneralHoursModel designMatCondition = new BusGeneralHoursModel();
                    designMatCondition.setBatId(cost.getBatId());
                    designMatCondition.setPart(cost.getPart());
                    designMatCondition.setMajor(cost.getMajor());
                    designMatCondition.setDataUseType(2);
                    designMatCondition.setTypes("34");
                    designMatCondition.setLaborTypes("17");
                    Integer dataCount = getDataDao.getBusGeneralHoursCountByCondition(designMatCondition);
                    if (dataCount > 0) {
                        cost.setDataSource("1");
                        getDataDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
                    }
                }
            }
            //检测该核算任务是否有数据
            Integer dataCount = getDataDao.getDataCountByBatId(busBudgetAccountingTask.getId());
            BusBudgetAccountingTaskModel order = new BusBudgetAccountingTaskModel();
            order.setId(busBudgetAccountingTask.getId());
            if (dataCount > 0) {
                order.setDataStatus(1);
            } else {
                order.setDataStatus(0);
            }
            getDataDao.updateBusBudgetAccountingTaskByPrimaryKeySelective(order);
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("获取成功！");
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("【获取数据异常】：" + ex.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("获取数据失败，请联系管理员！");
        }
        return jsonResult;
    }

    /**
     * getAbDataSourceByPrimaryKey
     * 依据主键获取数据源
     *
     * @param dsId 主键
     * @return 数据源信息
     * @author 徐一贺
     * @date 2020/9/18 11:10
     * @version 1.0
     */
    public BusDataSource getAbDataSourceByPrimaryKey(String dsId) {
        return getDataDao.getAbDataSourceByPrimaryKey(dsId);
    }

    /**
     * accountingDataListByMat
     * 获取对应任务对应数据源的材料数据
     *
     * @param param 参数
     * @return java.util.List 返回类型
     * @author 徐一贺
     * @date 2020/9/18 11:19
     * @version 1.0
     */
    public List<BusMaterialData> accountingDataListByMat(AbDataSourceModel param) {
        return getDataDao.accountingDataListByMat(param);
    }


    /**
     * BusBudgetAccountingCost
     * 生成成本项
     *
     * @param adtId 单据表主键
     * @return List<BusBudgetAccountingCost> 成本数据
     * @author 徐一贺
     * @date 2020/10/6 10:27
     * @version 1.0
     */
    @Transactional(rollbackFor = Exception.class)
    public List<BusBudgetAccountingCostModel> generateCostItems(String adtId) {
        String[] showOrderArray = {"（一）", "（二）", "（三）", "（四）", "（五）", "（六）", "（七）", "（八）", "（九）", "（十）",
                "（十一）", "（十二）", "（十三）", "（十四）", "（十五）", "（十六）", "（十七）", "（十八）", "（十九）", "（二十）",
                "（二十一）", "（二十二）", "（二十三）", "（二十四）", "（二十五）", "（二十六）", "（二十七）", "（二十八）", "（二十九）", "（三十）",
                "（三十一）", "（三十二）", "（三十三）", "（三十四）", "（三十五）", "（三十六）", "（三十七）", "（三十八）", "（三十九）", "（四十）",
                "（四十一）", "（四十二）", "（四十三）", "（四十四）", "（四十五）", "（四十六）", "（四十七）", "（四十八）", "（四十九）", "（五十）",
                "（五十一）", "（五十二）", "（五十三）", "（五十四）", "（五十五）", "（五十六）", "（五十七）", "（五十八）", "（五十九）", "（六十）",
                "（六十一）", "（六十二）", "（六十三）", "（六十四）", "（六十五）", "（六十六）", "（六十七）", "（六十八）", "（六十九）", "（七十）",
                "（七十一）", "（七十二）", "（七十三）", "（七十四）", "（七十五）", "（七十六）", "（七十七）", "（七十八）", "（七十九）", "（八十）",
                "（八十一）", "（八十二）", "（八十三）", "（八十四）", "（八十五）", "（八十六）", "（八十七）", "（八十八）", "（八十九）", "（九十）",
                "（九十一）", "（九十二）", "（九十三）", "（九十四）", "（九十五）", "（九十六）", "（九十七）", "（九十八）", "（九十九）", "（一百）",
                "（一百零一）", "（一百零二）", "（一百零三）", "（一百零四）", "（一百零五）", "（一百零六）", "（一百零七）", "（一百零八）", "（一百零九）", "（一百一十）"};
        String[] showOrderArray2 = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十",
                "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十",
                "二十一", "二十二", "二十三", "二十四", "二十五", "二十六", "二十七", "二十八", "二十九", "三十",
                "三十一", "三十二", "三十三", "三十四", "三十五", "三十六", "三十七", "三十八", "三十九", "四十",
                "四十一", "四十二", "四十三", "四十四", "四十五", "四十六", "四十七", "四十八", "四十九", "五十",
                "五十一", "五十二", "五十三", "五十四", "五十五", "五十六", "五十七", "五十八", "五十九", "六十",
                "六十一", "六十二", "六十三", "六十四", "六十五", "六十六", "六十七", "六十八", "六十九", "七十",
                "七十一", "七十二", "七十三", "七十四", "七十五", "七十六", "七十七", "七十八", "七十九", "八十",
                "八十一", "八十二", "八十三", "八十四", "八十五", "八十六", "八十七", "八十八", "八十九", "九十",
                "九十一", "九十二", "九十三", "九十四", "九十五", "九十六", "九十七", "九十八", "九十九", "一百",
                "一百零一", "一百零二", "一百零三", "一百零四", "一百零五", "一百零六", "一百零七", "一百零八", "一百零九", "一百一十"};
        BusBudgetAccountingTask busBudgetAccountingTask = getDataDao.getAbBudgetAccountingTaskByPrimaryKey(Integer.valueOf(adtId));
        String projectCode = busBudgetAccountingTask.getProCode();
        List<BusBudgetAccountingCostModel> busBudgetAccountingCosts = getDataDao.findBusBudgetAccountingCostByBatId(Integer.valueOf(adtId), 5);
        //获取成本模板数据-可以循环的列表
        List<BusCostTemplate> loopBusCostTemplateList = getDataDao.findBusCostTemplateByItemType(1);
        //获取成本模板数据-不可以循环的列表
        List<BusCostTemplate> noRecyclableBusCostTemplateList = getDataDao.findBusCostTemplateByItemType(2);
        //获取产品结构列表
        List<VwDsnProStrucModel> list = getDataDao.findPartInfoListByCode(projectCode);
        //专业列表
        List<String> majorList = new ArrayList<>();
        majorList.add("机械");
        majorList.add("流体");
        majorList.add("自动化");
        //获取产品结构不存在的专业
        List<String> notExistMajorList = new ArrayList<>();
        //获取产品结构不存在的专业列表
        for (String major : majorList) {
            int existCount = 0;
            for (VwDsnProStrucModel strucModel : list) {
                if (strucModel.getSpecial().equals(major)) {
                    existCount++;
                }
            }
            if (existCount == 0) {
                notExistMajorList.add(major);
            }
        }
        //获取该专业的产品结构都作废的专业列表
        List<String> invalidMajorList = new ArrayList<>();
        for (String major : majorList) {
            int invalidCount = 0;
            int majorCount = 0;
            for (VwDsnProStrucModel strucModel : list) {
                if (strucModel.getSpecial().equals(major)) {
                    majorCount++;
                    if (strucModel.getIsDel() == 2) {
                        invalidCount++;
                    }
                }
            }
            if (invalidCount != 0 && majorCount != 0 && invalidCount == majorCount) {
                invalidMajorList.add(major);
            }
        }
        if (busBudgetAccountingCosts.size() == 0) {
            //当前时间
            Date currentDate = new Date();
            //开始生成可以循环生成的部分
            Set<String> useMajor = new HashSet<>();
            //循环专业
            for (String major : majorList) {
                if (!notExistMajorList.contains(major)) {
                    //循环清单项-专业
                    for (BusCostTemplate busCostTemplate : loopBusCostTemplateList) {
                        if ("专业".equals(busCostTemplate.getCode())) {
                            BusBudgetAccountingCost costItem = new BusBudgetAccountingCost();
                            costItem.setName(busCostTemplate.getName().replace("专业", major));
                            costItem.setCode(busCostTemplate.getCode().replace("专业", major));
                            useMajor.add(major);
                            if (useMajor.size() == 1) {
                                costItem.setShowOrderNo("一");
                                costItem.setEditShowOrderNo("一");
                            } else if (useMajor.size() == 2) {
                                costItem.setShowOrderNo("二");
                                costItem.setEditShowOrderNo("二");
                            } else if (useMajor.size() == 3) {
                                costItem.setShowOrderNo("三");
                                costItem.setEditShowOrderNo("三");
                            }
                            costItem.setRank(busCostTemplate.getRank());
                            costItem.setNum(busCostTemplate.getNum());
                            costItem.setUnit(busCostTemplate.getUnit());
                            costItem.setPrice(busCostTemplate.getPrice());
                            costItem.setTotalPrice(busCostTemplate.getTotalPrice());
                            costItem.setMajor(major);
                            costItem.setPart(null);
                            costItem.setParentCode(busCostTemplate.getParentCode());
                            if (checkIsNotDiy(busCostTemplate.getCode())) {
                                costItem.setRemark(busCostTemplate.getRemark());
                            } else {
                                costItem.setDiyRemark(busCostTemplate.getRemark());
                            }
                            costItem.setItemType(busCostTemplate.getItemType());
                            costItem.setTextureEditFlag(busCostTemplate.getTextureEditFlag());
                            costItem.setPriceEditFlag(busCostTemplate.getPriceEditFlag());
                            costItem.setNumEditFlag(busCostTemplate.getNumEditFlag());
                            costItem.setTotalPriceFlag(busCostTemplate.getTotalPriceFlag());
                            costItem.setViewInfoFlag(busCostTemplate.getViewInfoFlag());
                            costItem.setDeleteFlag(busCostTemplate.getDeleteFlag());
                            costItem.setDisplayFlag(busCostTemplate.getDisplayFlag());
                            costItem.setBatId(busBudgetAccountingTask.getId());
                            costItem.setCreateTime(currentDate);
                            costItem.setTemplateId(busCostTemplate.getId());
                            costItem.setIsMajor(busCostTemplate.getIsMajor());
                            costItem.setIsPart(busCostTemplate.getIsPart());
                            costItem.setShowDataSource(busCostTemplate.getShowDataSource());
                            costItem.setShowFinishStatus(busCostTemplate.getShowFinishStatus());
                            if (invalidMajorList.contains(costItem.getMajor())) {
                                costItem.setIsInvalid(1);
                            } else {
                                costItem.setIsInvalid(0);
                            }
                            costItem.setDataSource("0");
                            costItem.setFinishStatus(1);
                            costItem.setRemarkEditFlag(busCostTemplate.getRemarkEditFlag());
                            costItem.setPriceEditFlag(busCostTemplate.getPriceEditFlag());
                            costItem.setTotalPrice(busCostTemplate.getTotalPrice());
                            costItem.setNumEditFlag(busCostTemplate.getNumEditFlag());
                            costItem.setOrderNo(busCostTemplate.getOrderNo());
                            costItem.setAmountDisplayModel(1);
                            getDataDao.insertBusBudgetAccountingCost(costItem);
                        }
                    }
                    int majorPartIndex = -1;
                    //循环产品结构
                    for (VwDsnProStrucModel vwDsnProStrucModel : list) {
                        if (vwDsnProStrucModel.getSpecial().equals(major)) {
                            majorPartIndex++;
                            //循环清单项
                            for (BusCostTemplate busCostTemplate : loopBusCostTemplateList) {
                                if (!"专业".equals(busCostTemplate.getCode())) {
                                    BusBudgetAccountingCost costItem = new BusBudgetAccountingCost();
                                    if ("专业-部分".equals(busCostTemplate.getCode())) {
                                        costItem.setShowOrderNo(showOrderArray[majorPartIndex]);
                                        costItem.setEditShowOrderNo(showOrderArray[majorPartIndex]);
                                    } else {
                                        costItem.setShowOrderNo(busCostTemplate.getShowOrderNo());
                                        costItem.setEditShowOrderNo(busCostTemplate.getShowOrderNo());
                                    }
                                    costItem.setName(busCostTemplate.getName().replace("专业", major).replace("部分", vwDsnProStrucModel.getProPart()));
                                    costItem.setCode(busCostTemplate.getCode().replace("专业", major).replace("部分", vwDsnProStrucModel.getProPart()));
                                    costItem.setRank(busCostTemplate.getRank());
                                    costItem.setNum(busCostTemplate.getNum());
                                    costItem.setUnit(busCostTemplate.getUnit());
                                    costItem.setPrice(busCostTemplate.getPrice());
                                    costItem.setTotalPrice(busCostTemplate.getTotalPrice());
                                    costItem.setMajor(major);
                                    costItem.setPart(vwDsnProStrucModel.getProPart());
                                    costItem.setParentCode(busCostTemplate.getParentCode().replace("专业", major).replace("部分", vwDsnProStrucModel.getProPart()));
                                    if (checkIsNotDiy(busCostTemplate.getCode())) {
                                        costItem.setRemark(busCostTemplate.getRemark());
                                    } else {
                                        costItem.setDiyRemark(busCostTemplate.getRemark());
                                    }
                                    costItem.setItemType(busCostTemplate.getItemType());
                                    costItem.setTextureEditFlag(busCostTemplate.getTextureEditFlag());
                                    costItem.setPriceEditFlag(busCostTemplate.getPriceEditFlag());
                                    costItem.setNumEditFlag(busCostTemplate.getNumEditFlag());
                                    costItem.setTotalPriceFlag(busCostTemplate.getTotalPriceFlag());
                                    costItem.setViewInfoFlag(busCostTemplate.getViewInfoFlag());
                                    costItem.setDeleteFlag(busCostTemplate.getDeleteFlag());
                                    costItem.setDisplayFlag(busCostTemplate.getDisplayFlag());
                                    costItem.setBatId(busBudgetAccountingTask.getId());
                                    costItem.setCreateTime(currentDate);
                                    costItem.setTemplateId(busCostTemplate.getId());
                                    costItem.setIsMajor(busCostTemplate.getIsMajor());
                                    costItem.setIsPart(busCostTemplate.getIsPart());
                                    costItem.setIsInvalid(busCostTemplate.getIsInvalid());
                                    costItem.setShowDataSource(busCostTemplate.getShowDataSource());
                                    costItem.setShowFinishStatus(busCostTemplate.getShowFinishStatus());
                                    if (vwDsnProStrucModel.getIsDel() == 2) {
                                        costItem.setIsInvalid(1);
                                    } else {
                                        costItem.setIsInvalid(0);
                                    }
                                    costItem.setDataSource("0");
                                    costItem.setFinishStatus(1);
                                    costItem.setRemarkEditFlag(busCostTemplate.getRemarkEditFlag());
                                    costItem.setPriceEditFlag(busCostTemplate.getPriceEditFlag());
                                    costItem.setTotalPrice(busCostTemplate.getTotalPrice());
                                    costItem.setNumEditFlag(busCostTemplate.getNumEditFlag());
                                    costItem.setAmountDisplayModel(1);
                                    getDataDao.insertBusBudgetAccountingCost(costItem);
                                }
                            }
                        } else {
                            majorPartIndex = -1;
                        }
                    }
                }
            }
            int index = useMajor.size();
            if (notExistMajorList.size() < 3) {
                //生成固定项
                for (BusCostTemplate busCostTemplate : noRecyclableBusCostTemplateList) {
                    BusBudgetAccountingCost costItem = new BusBudgetAccountingCost();
                    costItem.setName(busCostTemplate.getName());
                    costItem.setCode(busCostTemplate.getCode());
                    if (!"小计".equals(busCostTemplate.getCode()) && "合计".equals(busCostTemplate.getParentCode())) {
                        if (index > 0) {
                            costItem.setShowOrderNo(showOrderArray2[index]);
                            costItem.setEditShowOrderNo(showOrderArray2[index]);
                            index++;
                        }
                    } else {
                        costItem.setShowOrderNo(busCostTemplate.getShowOrderNo());
                        costItem.setEditShowOrderNo(busCostTemplate.getShowOrderNo());
                    }

                    costItem.setRank(busCostTemplate.getRank());
                    costItem.setNum(busCostTemplate.getNum());
                    costItem.setUnit(busCostTemplate.getUnit());
                    costItem.setPrice(busCostTemplate.getPrice());
                    costItem.setTotalPrice(busCostTemplate.getTotalPrice());
                    if ("备品备件".equals(busCostTemplate.getCode())) {
                        costItem.setPart("备品备件");
                    } else if ("随机备件".equals(busCostTemplate.getCode())) {
                        costItem.setPart("随机备件");
                    } else {
                        costItem.setPart(null);
                    }
                    costItem.setMajor(null);
                    costItem.setParentCode(busCostTemplate.getParentCode());
                    if (checkIsNotDiy(busCostTemplate.getCode())) {
                        costItem.setRemark(busCostTemplate.getRemark());
                    } else {
                        costItem.setDiyRemark(busCostTemplate.getRemark());
                    }
                    costItem.setItemType(busCostTemplate.getItemType());
                    costItem.setTextureEditFlag(busCostTemplate.getTextureEditFlag());
                    costItem.setPriceEditFlag(busCostTemplate.getPriceEditFlag());
                    costItem.setNumEditFlag(busCostTemplate.getNumEditFlag());
                    costItem.setTotalPriceFlag(busCostTemplate.getTotalPriceFlag());
                    costItem.setViewInfoFlag(busCostTemplate.getViewInfoFlag());
                    costItem.setDeleteFlag(busCostTemplate.getDeleteFlag());
                    costItem.setDisplayFlag(busCostTemplate.getDisplayFlag());
                    costItem.setBatId(busBudgetAccountingTask.getId());
                    costItem.setCreateTime(currentDate);
                    costItem.setTemplateId(busCostTemplate.getId());
                    costItem.setIsMajor(busCostTemplate.getIsMajor());
                    costItem.setIsPart(busCostTemplate.getIsPart());
                    costItem.setIsInvalid(busCostTemplate.getIsInvalid());
                    costItem.setShowDataSource(busCostTemplate.getShowDataSource());
                    costItem.setShowFinishStatus(busCostTemplate.getShowFinishStatus());
                    costItem.setDataSource("0");
                    costItem.setFinishStatus(1);
                    costItem.setRemarkEditFlag(busCostTemplate.getRemarkEditFlag());
                    costItem.setPriceEditFlag(busCostTemplate.getPriceEditFlag());
                    costItem.setTotalPrice(busCostTemplate.getTotalPrice());
                    costItem.setNumEditFlag(busCostTemplate.getNumEditFlag());
                    costItem.setAmountDisplayModel(1);
                    getDataDao.insertBusBudgetAccountingCost(costItem);
                }
            }
//            //获取模板
//            List<BusCostTemplate> busCostTemplates = accountingDao.getBusCostTemplateList(1);
//            //生成过的专业Set
//            Set<String> majorSet = new HashSet<>();
//            //创建查看审核成本清单并计算核算数据
//            for (String major : majorList) {
//                for (BusCostTemplate busCostTemplate : busCostTemplates) {
//                    BusBudgetAccountingCost costItem = new BusBudgetAccountingCost();
//                    if (busCostTemplate.getCode().contains("专业")) {
//                        majorSet.add(major);
//                        if ("专业".equals(busCostTemplate.getCode())) {
//                            if (majorSet.size() == 1) {
//                                costItem.setShowOrderNo("一");
//                            } else if (majorSet.size() == 2) {
//                                costItem.setShowOrderNo("二");
//                            } else if (majorSet.size() == 3) {
//                                costItem.setShowOrderNo("三");
//                            }
//                        } else {
//                            costItem.setShowOrderNo(busCostTemplate.getShowOrderNo());
//                        }
//                        costItem.setCode(busCostTemplate.getCode().replace("专业", major));
//                        costItem.setName(busCostTemplate.getName().replace("专业", major));
//                        costItem.setCode(busCostTemplate.getCode().replace("专业", major));
//                        costItem.setRank(busCostTemplate.getRank());
//                        costItem.setNum(busCostTemplate.getNum());
//                        costItem.setUnit(busCostTemplate.getUnit());
//                        costItem.setPrice(busCostTemplate.getPrice());
//                        costItem.setTotalPrice(busCostTemplate.getTotalPrice());
//                        costItem.setMajor(major);
//                        costItem.setPart(null);
//                        costItem.setParentCode(busCostTemplate.getParentCode().replace("专业", major));
//                        costItem.setRemark(busCostTemplate.getRemark());
//                        costItem.setItemType(busCostTemplate.getItemType());
//                        costItem.setTextureEditFlag(busCostTemplate.getTextureEditFlag());
//                        costItem.setPriceEditFlag(busCostTemplate.getPriceEditFlag());
//                        costItem.setNumEditFlag(busCostTemplate.getNumEditFlag());
//                        costItem.setTotalPriceFlag(busCostTemplate.getTotalPriceFlag());
//                        costItem.setViewInfoFlag(busCostTemplate.getViewInfoFlag());
//                        costItem.setDeleteFlag(busCostTemplate.getDeleteFlag());
//                        costItem.setDisplayFlag(busCostTemplate.getDisplayFlag());
//                        costItem.setBatId(busBudgetAccountingTask.getId());
//                        costItem.setCreateTime(currentDate);
//                        costItem.setTemplateId(busCostTemplate.getId());
//                        costItem.setIsMajor(busCostTemplate.getIsMajor());
//                        costItem.setIsPart(busCostTemplate.getIsPart());
//                        costItem.setIsInvalid(busCostTemplate.getIsInvalid());
//                        costItem.setShowDataSource(busCostTemplate.getShowDataSource());
//                        costItem.setShowFinishStatus(busCostTemplate.getShowFinishStatus());
//                        costItem.setIsInvalid(0);
//                        costItem.setDataSource("0");
//                        costItem.setFinishStatus(1);
//                        costItem.setRemarkEditFlag(busCostTemplate.getRemarkEditFlag());
//                        costItem.setPriceEditFlag(busCostTemplate.getPriceEditFlag());
//                        costItem.setTotalPrice(busCostTemplate.getTotalPrice());
//                        costItem.setNumEditFlag(busCostTemplate.getNumEditFlag());
//                        getDataDao.insertBusBudgetAccountingCost(costItem);
//                    }
//                }
//            }
//            int index2 = majorSet.size();
//            for (BusCostTemplate busCostTemplate : busCostTemplates) {
//                if (!busCostTemplate.getCode().contains("专业")) {
//                    BusBudgetAccountingCost costItem = new BusBudgetAccountingCost();
//                    if (!"小计".equals(busCostTemplate.getCode()) && "合计".equals(busCostTemplate.getParentCode())) {
//                        if (index2 > 0) {
//                            costItem.setShowOrderNo(showOrderArray[index2]);
//                            index2++;
//                        }
//                    } else {
//                        costItem.setShowOrderNo(busCostTemplate.getShowOrderNo());
//                    }
//                    costItem.setCode(busCostTemplate.getCode());
//                    costItem.setName(busCostTemplate.getName());
//                    costItem.setCode(busCostTemplate.getCode());
//                    costItem.setRank(busCostTemplate.getRank());
//                    costItem.setNum(busCostTemplate.getNum());
//                    costItem.setUnit(busCostTemplate.getUnit());
//                    costItem.setPrice(busCostTemplate.getPrice());
//                    costItem.setTotalPrice(busCostTemplate.getTotalPrice());
//                    costItem.setMajor(null);
//                    costItem.setPart(null);
//                    costItem.setParentCode(busCostTemplate.getParentCode());
//                    costItem.setRemark(busCostTemplate.getRemark());
//                    costItem.setItemType(busCostTemplate.getItemType());
//                    costItem.setTextureEditFlag(busCostTemplate.getTextureEditFlag());
//                    costItem.setPriceEditFlag(busCostTemplate.getPriceEditFlag());
//                    costItem.setNumEditFlag(busCostTemplate.getNumEditFlag());
//                    costItem.setTotalPriceFlag(busCostTemplate.getTotalPriceFlag());
//                    costItem.setViewInfoFlag(busCostTemplate.getViewInfoFlag());
//                    costItem.setDeleteFlag(busCostTemplate.getDeleteFlag());
//                    costItem.setDisplayFlag(busCostTemplate.getDisplayFlag());
//                    costItem.setBatId(busBudgetAccountingTask.getId());
//                    costItem.setCreateTime(currentDate);
//                    costItem.setTemplateId(busCostTemplate.getId());
//                    costItem.setIsMajor(busCostTemplate.getIsMajor());
//                    costItem.setIsPart(busCostTemplate.getIsPart());
//                    costItem.setIsInvalid(busCostTemplate.getIsInvalid());
//                    costItem.setShowDataSource(busCostTemplate.getShowDataSource());
//                    costItem.setShowFinishStatus(busCostTemplate.getShowFinishStatus());
//                    costItem.setIsInvalid(0);
//                    costItem.setDataSource("0");
//                    costItem.setFinishStatus(1);
//                    costItem.setRemarkEditFlag(busCostTemplate.getRemarkEditFlag());
//                    costItem.setPriceEditFlag(busCostTemplate.getPriceEditFlag());
//                    costItem.setTotalPrice(busCostTemplate.getTotalPrice());
//                    costItem.setNumEditFlag(busCostTemplate.getNumEditFlag());
//                    getDataDao.insertBusBudgetAccountingCost(costItem);
//                }
//            }
            List<BusBudgetAccountingCostModel> busBudgetAccountingCostList = getDataDao.findBusBudgetAccountingCostByBatId(Integer.valueOf(adtId), 5);
            return busBudgetAccountingCostList;
        } else {
            return busBudgetAccountingCosts;
        }
    }

    /**
     * checkIsNotDiy 检测成本项码是否把备注生成到
     *
     * @param code
     * @return java.lang.Boolean
     * @throws
     * @author 徐一贺
     * @date 2020/12/11 10:51
     */
    private Boolean checkIsNotDiy(String code) {
        if (code.contains("材料采购费") && "-材料采购费".equals(code.substring(code.lastIndexOf("-")))) {
            return true;
        } else if (code.contains("碳钢") && "-碳钢".equals(code.substring(code.lastIndexOf("-")))) {
            return true;
        } else if (code.contains("不锈钢") && "-不锈钢".equals(code.substring(code.lastIndexOf("-")))) {
            return true;
        } else if (code.contains("铝材") && "-铝材".equals(code.substring(code.lastIndexOf("-")))) {
            return true;
        } else if (code.contains("废料回收费") && "-废料回收费".equals(code.substring(code.lastIndexOf("-")))) {
            return true;
        } else if (code.contains("制造费") && "-制造费".equals(code.substring(code.lastIndexOf("-")))) {
            return true;
        } else if (code.contains("现场安装调试费") && "-现场安装调试费".equals(code.substring(code.lastIndexOf("-")))) {
            return true;
        } else if (code.contains("管理费") && "管理费".equals(code)) {
            return true;
        } else if (code.contains("合计") && "合计".equals(code)) {
            return true;
        } else {
            return false;
        }
    }


    /**
     * genBusBudgetAccountingBasicInfoConfigList
     * 生成基础配置项
     *
     * @param batId 单据表主键
     * @return java.util.List 返回类型
     * @author 徐一贺
     * @date 2020/10/7 9:22
     * @version 1.0
     */
    @Transactional(rollbackFor = Exception.class)
    public List<BusBudgetAccountingBasicInfoConfig> genBusBudgetAccountingBasicInfoConfigList(Integer batId) {
        List<BusBudgetAccountingBasicInfoConfig> busBudgetAccountingBasicInfoConfigList = getDataDao.findBusBudgetAccountingBasicInfoConfigListByBatId(batId);
        if (busBudgetAccountingBasicInfoConfigList.size() == 0) {
            //获取成本模板数据
            List<BusBudgetAccountingBasicInfoConfigTemplate> busBudgetAccountingBasicInfoConfigTemplateList = getDataDao.findBusBudgetAccountingBasicInfoConfigTemplate();
            for (BusBudgetAccountingBasicInfoConfigTemplate busBudgetAccountingBasicInfoConfigTemplate : busBudgetAccountingBasicInfoConfigTemplateList) {
                BusBudgetAccountingBasicInfoConfig busBudgetAccountingBasicInfoConfig = new BusBudgetAccountingBasicInfoConfig();
                busBudgetAccountingBasicInfoConfig.setBatId(batId);
                busBudgetAccountingBasicInfoConfig.setCode(busBudgetAccountingBasicInfoConfigTemplate.getCode());
                busBudgetAccountingBasicInfoConfig.setName(busBudgetAccountingBasicInfoConfigTemplate.getName());
                busBudgetAccountingBasicInfoConfig.setOrderNo(busBudgetAccountingBasicInfoConfigTemplate.getOrderNo());
                busBudgetAccountingBasicInfoConfig.setValue(busBudgetAccountingBasicInfoConfigTemplate.getValue());
                busBudgetAccountingBasicInfoConfig.setUnit(busBudgetAccountingBasicInfoConfigTemplate.getUnit());
                getDataDao.insertBusBudgetAccountingBasicInfoConfig(busBudgetAccountingBasicInfoConfig);
            }
            busBudgetAccountingBasicInfoConfigList = getDataDao.findBusBudgetAccountingBasicInfoConfigListByBatId(batId);
        }
        return busBudgetAccountingBasicInfoConfigList;
    }


    /**
     * findDesignHours
     * 获取设计工时数据
     *
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/17 11:13
     * @version 1.0
     */
    public List<BusGeneralHoursModel> findDesignHoursList(BusGeneralHoursModel param) {
        return getDataDao.findDesignHoursList(param);
    }

    /**
     * findWeightWeightList
     * 获取设计重量数据
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/17 11:21
     * @version 1.0
     */
    public List<BusGeneralHoursModel> findWeightWeightList(BusGeneralHoursModel param) {
        return getDataDao.findWeightWeightList(param);
    }

    /**
     * clearData
     * 清空指定数据源的数据
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/17 12:58
     * @version 1.0
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult clearData(BusGeneralHoursModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            BusBudgetAccountingTask busBudgetAccountingTask = getDataDao.getBusBudgetAccountingTaskByPrimaryKey(param.getBatId());
            //设置是核算 还是预算 还是概算
            if (busBudgetAccountingTask.getTaskType() == 1) {
                param.setDataUseType(1);
            } else if (busBudgetAccountingTask.getTaskType() == 2) {
                param.setDataUseType(2);
            } else if (busBudgetAccountingTask.getTaskType() == 3) {
                param.setDataUseType(3);
            }
            BusDataSource dataSource = getDataDao.getDataSourceByPrimaryKey(param.getDsId());
            //获取专业
            String major = dataSource.getMajor();
            switch (dataSource.getDataCode()) {
                case "ds001":
                    if ("机械".equals(major)) {
                        param.setTypes("1");
                    } else if ("流体".equals(major)) {
                        param.setTypes("2");
                    } else if ("自动化".equals(major)) {
                        param.setTypes("3");
                    }
                    param.setLaborTypes("1,2,3,20");
                    break;
                case "ds002":
                    break;
                case "ds003":
                    break;
                case "ds004":
                    break;
                case "ds005":
                    break;
                case "ds006":
                    if ("机械".equals(major)) {
                        param.setTypes("7");
                    } else if ("流体".equals(major)) {
                        param.setTypes("8");
                    } else if ("自动化".equals(major)) {
                        param.setTypes("9");
                    }
                    param.setLaborTypes("4,5");
                    break;
                case "ds007":
                    if ("机械".equals(major)) {
                        param.setTypes("13");
                    } else if ("流体".equals(major)) {
                        param.setTypes("14");
                    } else if ("自动化".equals(major)) {
                        param.setTypes("15");
                    }
                    param.setLaborTypes("6.7");
                    break;
                case "ds009":
                    if ("机械".equals(major)) {
                        param.setTypes("19");
                    } else if ("流体".equals(major)) {
                        param.setTypes("20");
                    } else if ("自动化".equals(major)) {
                        param.setTypes("21");
                    }
                    param.setLaborTypes("8");
                    break;
                case "ds010":
                    if ("机械".equals(major)) {
                        param.setTypes("25");
                    } else if ("流体".equals(major)) {
                        param.setTypes("26");
                    } else if ("自动化".equals(major)) {
                        param.setTypes("27");
                    }
                    param.setLaborTypes("9,10,11,12");
                    break;
                case "ds011":
                    if ("机械".equals(major)) {
                        param.setTypes("31");
                    } else if ("流体".equals(major)) {
                        param.setTypes("32");
                    } else if ("自动化".equals(major)) {
                        param.setTypes("33");
                    }
                    param.setLaborTypes("13,14");
                    break;
                case "ds012":
                    param.setTypes("34");
                    param.setLaborTypes("15,16,17");
                    break;
                case "ds013":
                    if ("机械".equals(major)) {
                        param.setTypes("38");
                    } else if ("流体".equals(major)) {
                        param.setTypes("39");
                    } else if ("自动化".equals(major)) {
                        param.setTypes("40");
                    }
                    param.setLaborTypes("18,19");
                    break;
            }

            getDataDao.deleteBusGeneralHoursByDsId(param);
            dataSource.setReceiveStatus(0);
            dataSource.setDataStatus(null);
            dataSource.setReceiveDate(null);
            getDataDao.updateBusDataSourceByPrimaryKey(dataSource);
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("清空成功！");
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("清空失败！请联系管理员！");
            log.error(e.getMessage());
        }
        return jsonResult;
    }

    /**
     * clearMacData
     * 清空指定数据源的数据
     *
     * @param dsId 数据源主键
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/17 12:58
     * @version 1.0
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult clearMacData(Integer dsId) {
        JsonResult jsonResult = new JsonResult();
        try {
            getDataDao.deleteBusMachiningHoursByDsId(dsId);
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("清空成功！");
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("清空失败！请联系管理员！");
            log.error(e.getMessage());
        }
        return jsonResult;
    }

    /**
     * clearDataByMat
     * 清空指定数据源的数据
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/17 12:58
     * @version 1.0
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult clearDataByMat(BusMaterialDataModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            getDataDao.deleteBusMaterialDataByDsId(param);
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("清空成功！");
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("清空失败！请联系管理员！");
            log.error(e.getMessage());
        }
        return jsonResult;
    }

    /**
     * findBuyList
     * 根据数据源和单据表主键获取外购件列表
     *
     * @param param 参数
     * @return java.util.List<com.zhongwang.business.module.estimateBudgetAccountingManage.model.BusMaterialDataModel>
     * @author 徐一贺
     * @date 2020/10/23 18:14
     * @version 1.0
     */
    public List<BusMaterialDataModel> findBuyList(BusMaterialDataModel param) {
        param.setDataUseType(2);
        return getDataDao.findBuyList(param);
    }

    /**
     * findHours
     * 获取工时列表
     *
     * @param param 参数
     * @return java.util.List<com.zhongwang.business.module.estimateBudgetAccountingManage.model.BusGeneralHoursModel>
     * @author 徐一贺
     * @date 2020/10/23 20:24
     * @version 1.0
     */
    public List<BusGeneralHoursModel> findHours(BusGeneralHoursModel param) {
        return getDataDao.findHours(param);
    }

    /**
     * getDataSourceByPrimaryKey
     * 根据主键获取数据源信息
     *
     * @param dsId 数据源主键
     * @return com.zhongwang.business.gen.entity.BusDataSource
     * @author 徐一贺
     * @date 2020/10/23 20:51
     * @version 1.0
     */
    public BusDataSource getDataSourceByPrimaryKey(Integer dsId) {
        return getDataDao.getBusDataSourceByPrimaryKey(dsId);
    }

    /**
     * getBusBudgetAccountingTaskByPrimaryKey
     * 根据主键获取单据表信息
     *
     * @param batId 单据表主键
     * @return com.zhongwang.business.gen.entity.BusBudgetAccountingTask
     * @author 徐一贺
     * @date 2020/10/24 8:02
     * @version 1.0
     */
    public BusBudgetAccountingTaskModel getBusBudgetAccountingTaskByPrimaryKey(Integer batId) {
        return getDataDao.getBusBudgetAccountingTaskByPrimaryKey(batId);
    }

    /**
     * getMajorFromBproductStructureByFkIdAndPartName
     * 获取专业
     *
     * @param proCode 项目号
     * @param part    部分
     * @return java.lang.String
     * @author 徐一贺
     * @date 2020/10/24 8:05
     * @version 1.0
     */
    public String getMajorFromBproductStructureByFkIdAndPartName(String proCode, String part) {
        return getDataDao.getMajorFromBproductStructureByFkIdAndPartName(proCode, part);
    }


    /**
     * findMacHours
     * 获取机加数据列表
     *
     * @param param 参数
     * @return java.util.List<com.zhongwang.business.module.estimateBudgetAccountingManage.model.BusMachiningHoursModel>
     * @author 徐一贺
     * @date 2020/10/24 8:55
     * @version 1.0
     */
    public List<Map<String, String>> findMacHours(BusMachiningHoursModel param) {
        return getDataDao.findMacHours(param);
    }

    /**
     * updateDataStatus
     * 根据主键更改数据源状态
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/26 10:55
     * @version 1.0
     */
    public JsonResult updateDataStatus(BusDataSourceModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            getDataDao.updateDataStatusByParamaryKey(param);
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("操作成功！");
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("操作失败！");
            log.error(e.getMessage());
        }
        return jsonResult;
    }

    /**
     * checkIsJump
     * 检测该项目下是否存在产品结构，产品结构来自于PDM表
     *
     * @param code 设备代码
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/30 14:02
     * @version 1.0
     */
    public JsonResult checkPartIsExist(String code) {
        JsonResult jsonResult = new JsonResult();
        try {
            //检测是否存在产品架构
            List<VwDsnProStrucModel> list = getDataDao.findPartInfoListByCode(code);
            if (list.size() > 0) {
                //检测是否在审核流程定义表中属于审核终点如果是审核终点不可创建核算成本清单
                if (getDataDao.checkIsEnd(ShiroUtils.getUserId()) == null || getDataDao.checkIsEnd(ShiroUtils.getUserId()).getComp() == 0) {
                    jsonResult.setType(JsonResult.ResultType.SUCCESS);
                } else {
                    jsonResult.setType(JsonResult.ResultType.ERROR);
                    jsonResult.setMsg("尊敬的用户，因为您是流程最终审核级别用户，所以无法创建或者取消保存成本清单！");
                }

            } else {
                jsonResult.setType(JsonResult.ResultType.ERROR);
                jsonResult.setMsg("该项目产品结构不存在，无法核算！");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("系统错误请联系管理员！");
        }
        return jsonResult;
    }

    /**
     * getBusBudgetAccountingTaskByCondition
     * 根据条件获取单据表信息
     *
     * @param budgetAccountingTaskCondition 条件
     * @return com.zhongwang.business.gen.entity.BusBudgetAccountingTask
     * @author 徐一贺
     * @date 2020/10/31 8:20
     * @version 1.0
     */
    public BusBudgetAccountingTask getBusBudgetAccountingTaskByCondition(BusBudgetAccountingTask budgetAccountingTaskCondition) {
        return getDataDao.getBusBudgetAccountingTaskByCondition(budgetAccountingTaskCondition);
    }

    /**
     * getAccountingEquipmentTotalWeightByBatId
     * 根据单据表获取核算设备总重
     *
     * @param BatId 单据表主键
     * @return java.math.BigDecimal
     * @author 徐一贺
     * @date 2020/11/10 16:02
     * @version 1.0
     */
    public BigDecimal getAccountingEquipmentTotalWeightByBatId(Integer BatId) {
        return getDataDao.getAccountingEquipmentTotalWeightByBatId(BatId);
    }

    /**
     * getAccountingEquipmentTotalNetWeightByBatId
     * 根据单据表获取核算设备总净重
     *
     * @param BatId 单据表主键
     * @return java.math.BigDecimal
     * @author 徐一贺
     * @date 2020/11/10 16:02
     * @version 1.0
     */
    public BigDecimal getAccountingEquipmentTotalNetWeightByBatId(Integer BatId) {
        return getDataDao.getAccountingEquipmentTotalNetWeightByBatId(BatId);
    }

    /**
     * cancelSave
     * 取消保存
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/10 18:19
     * @version 1.0
     */
    public JsonResult cancelSave(BusBudgetAccountingTaskModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            param.setIsSave(0);
            getDataDao.updateBusBudgetAccountingTaskByPrimaryKeySelective(param);
            BusBudgetAccountingTaskModel task = getDataDao.getBusBudgetAccountingTaskByPrimaryKey(param.getId());
            logService.saveLog("核算清单调整", "取消保存项目号为【" + task.getProCode() + "】的核算成本清单。");
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("取消保存成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("取消保存失败！");
        }
        return jsonResult;
    }

    /**
     * createCostSheet
     * 创建成本清单
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/11 11:01
     * @version 1.0
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult createCostSheet(BusBudgetAccountingTaskModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            Date currentTime = new Date();
            BusBudgetAccountingTask budgetAccountingTaskCondition = new BusBudgetAccountingTask();
            budgetAccountingTaskCondition.setTaskId(6);
            budgetAccountingTaskCondition.setTaskType(2);
            budgetAccountingTaskCondition.setProCode(param.getProCode());
            //获取核算任务
            Task task = getDataDao.getTaskByCodeAndTaskType(param.getProCode(), 6);
            if (task != null) {
                BusBudgetAccountingTask newOrder = new BusBudgetAccountingTask();
                newOrder.setStartDate(currentTime);
                newOrder.setTaskType(2);
                newOrder.setTaskUid(ShiroUtils.getUserId());
                newOrder.setProCode(param.getProCode());
                newOrder.setIsSave(0);
                newOrder.setSubmitStatus(0);
                newOrder.setTaskId(task.getId());
                newOrder.setStartDate(currentTime);
                BusBudgetAccountingTask busBudgetAccountingTask = getDataDao.getBusBudgetAccountingTaskByCondition(newOrder);
                if (busBudgetAccountingTask == null) {
                    getDataDao.insertInitTaskOrder(newOrder);
                }
                busBudgetAccountingTask = getDataDao.getBusBudgetAccountingTaskByCondition(newOrder);
                //如果没有成本清单，则生成成本清单
                List<BusBudgetAccountingCostModel> busBudgetAccountingCosts = generateCostItems(busBudgetAccountingTask.getId().toString());
                //通过模板生成基础参数数据
                List<BusBudgetAccountingBasicInfoConfig> busBudgetAccountingBasicInfoConfigList = genBusBudgetAccountingBasicInfoConfigList(Integer.valueOf(busBudgetAccountingTask.getId().toString()));
                if (busBudgetAccountingCosts.size() > 0 && busBudgetAccountingBasicInfoConfigList.size() > 0) {
                    jsonResult.setType(JsonResult.ResultType.SUCCESS);
                    jsonResult.setMsg("创建成本清单成功！");
                    logService.saveLog("核算成本清单调整", "创建了项目号为" + param.getProCode() + "的成本清单。");
                    task.setKeyperson(ShiroUtils.getUser().getName());
                    task.setKeypersonid(ShiroUtils.getUserId());
                    task.setBegindate(currentTime);
                    task.setTstatus(2);
                    getDataDao.updateTaskInfoByPrimaryKey(task);
                    //生成数据源
                    generateOrderData(param.getProCode());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("创建成本清单失败！");
        }
        return jsonResult;
    }

    /**
     * findBusBudgetAccountingCostListByBatId
     * 根据BatId获取成本清单列表
     *
     * @param batId 单据表主键
     * @return java.util.List<com.zhongwang.business.gen.entity.BusBudgetAccountingCost>
     * @author 徐一贺
     * @date 2020/11/11 12:34
     * @version 1.0
     */
    public List<BusBudgetAccountingCostModel> findBusBudgetAccountingCostListByBatId(String batId, Integer verId) {
        return getDataDao.findBusBudgetAccountingCostByBatId(Integer.valueOf(batId), verId);
    }

    /**
     * findBusBudgetAccountingBasicInfoConfigByBatID
     * 根据BatId获取基础配置信息列表
     *
     * @param batId 单据表主键
     * @return java.util.List<com.zhongwang.business.gen.entity.BusBudgetAccountingBasicInfoConfig>
     * @author 徐一贺
     * @date 2020/11/11 12:35
     * @version 1.0
     */
    public List<BusBudgetAccountingBasicInfoConfig> findBusBudgetAccountingBasicInfoConfigByBatId(Integer batId) {
        return getDataDao.findBusBudgetAccountingBasicInfoConfigListByBatId(batId);
    }

    /**
     * getRejectInfoBy 获取驳回信息
     *
     * @param bllId      单据表主键
     * @param submitUser 当前用户ID
     * @return com.zhongwang.business.module.estimateBudgetAccountingManage.model.AccountingProjectModel
     * @author 徐一贺
     * @date 2020/11/24 20:34
     */
    public AccountingProjectModel getRejectInfoBy(Integer bllId, Integer submitUser) {
        return getDataDao.getRejectInfoBy(bllId, submitUser);
    }
    /**
     * AccountingProjectModel 获取驳回信息
     *
     * @param bllId      单据表主键
     * @param submitUser 当前用户ID
     * @return com.zhongwang.business.module.estimateBudgetAccountingManage.model.AccountingProjectModel
     * @author 徐一贺
     * @date 2020/11/24 20:34
     */
    public AccountingProjectModel getEstimatingRejectInfoBy(Integer bllId, Integer submitUser) {
        return getDataDao.getEstimatingRejectInfoBy(bllId, submitUser);
    }

    /**
     * updateBusBudgetAccountingTaskByPrimaryKey 根据主键更新单据表信息
     *
     * @param task id是主键
     * @return void
     * @throws
     * @author 徐一贺
     * @date 2020/11/25 8:01
     */
    public int updateBusBudgetAccountingTaskByPrimaryKey(BusBudgetAccountingTaskModel task) {
        if (task.getIsSave() == 0) {
            logService.saveLog("核算清单调整", "取消保存项目号为【" + task.getProCode() + "】的核算成本清单。");
        }
        return getDataDao.updateBusBudgetAccountingTaskByPrimaryKeySelective(task);
    }

    /**
     * accountingAdopt 核算审批通过
     *
     * @param param 参数
     * @return jcom.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/25 15:51
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult accountingApproval(AccountingProjectModel param) {
        JsonResult jsonResult = new JsonResult();
        Date currentTime = new Date();
        try {
            //获取单据表信息
            BusBudgetAccountingTaskModel order = getDataDao.getBusBudgetAccountingTaskModelByVerifyProcessPrimarykey(param.getId());
            param.setAppTime(currentTime);
            getDataDao.updVerifyProcess(param);
            //根据当前的节点，OK NG+意见
            //1·OK
            AccountingProjectModel nowProcess = getDataDao.findVerifyProcess(param.getId());
            //获取审核级别
            AccountingProjectModel auditLevelModel = getDataDao.getAuditLevelByNowNode(nowProcess);
            //获取审核单据表
            AccountingProjectModel auditOrder = getDataDao.getAuditOrderByBllId(order.getId());
            if ("部长级".equals(auditLevelModel.getAppLevelName())) {
                auditOrder.setApprover(auditLevelModel.getName());
                getDataDao.updateSheetDetailByPrimaryKey(auditOrder);
                order.setApproverUid(auditLevelModel.getUid());
                order.setApprovalDate(currentTime);
            } else if ("科长级".equals(auditLevelModel.getAppLevelName())) {
                auditOrder.setReviewer(auditLevelModel.getName());
                getDataDao.updateSheetDetailByPrimaryKey(auditOrder);
                order.setReviewerUid(auditLevelModel.getUid());
            }
            getDataDao.updateBusBudgetAccountingTaskByPrimaryKeySelective(order);

            //循环判断 当前的账号所在的流程节点；
            User user = ShiroUtils.getUser();
            List<AuditProcessModel> nowUserNodeInfo = getDataDao.findAppNodeInfoByUserId(user.getId());
            /**
             * 审批状态为2时；代表通过
             */
            if (param.getAppStatus() == 2) {
                /**
                 * 下一个节点=0 就是当前是最后的节点了，需要修改业务主表的状态值
                 */
                if (nowProcess.getStart() == 0) {
                    //1.1·当前是否是最后一个节点
                    //1.1.1·修改业务主表的状态值

                    /**
                     * bus_accounting_task submit_status: 1=未提交，2=待审核，3=审核通过，100=审核不通过
                     */
                    order.setSubmitStatus(3);
                    getDataDao.updateBusBudgetAccountingTaskByPrimaryKeySelective(order);
                    Task task = getDataDao.getTaskByPrimaryKey(order.getTaskId());
                    task.setEnddate(currentTime);
                    task.setTstatus(3);
                    getDataDao.updateTaskInfoByPrimaryKey(task);
                } else {
                    //1.2·找到下一个节点、下下个节点、审批人
                    List<AuditProcessModel> appList = getDataDao.findAppNodeInfo(nowUserNodeInfo.get(0).getOrderNo());
                    /**
                     * 根据我当前登录的账号，和流程配置的级别，找到那个人、
                     */
                    AuditProcessModel addAppInfo = new AuditProcessModel();

                    int pid = getDataDao.getNowLevelByUserId(user.getId());
                    /**
                     * 执行递归查询
                     */
                    addAppInfo.setVerifier(getPid(appList.get(0).getPost(), pid));
                    addAppInfo.setNowNode(appList.get(0).getId());
                    addAppInfo.setOrderNo(appList.get(0).getOrderNo());

                    if (appList != null && appList.size() >= 2) {
                        addAppInfo.setStart(appList.get(1).getId());
                    } else {
                        addAppInfo.setStart(0);
                    }
                    //下一个节点的，上一个节点是现在的id
                    addAppInfo.setComp(nowProcess.getNowNode());
                    addAppInfo.setCode("HS001");
                    addAppInfo.setSheetId(nowProcess.getSheetId());
                    addAppInfo.setAppStatus(1);
                    getDataDao.insertVerifyProcess(addAppInfo);
                }
                logService.saveLog("核算清单审核", ShiroUtils.getUser().getName() + "审核通过了" + order.getFounder() + "创建的项目号为" + order.getProCode() + "的核算清单！");
            } else {
                //2·NG+意见
                //2.1·存储当前的状态+结果
                if (nowProcess.getComp() == 0) {
                    //2.2.1·如果上一个是提交的话，修改业务主表的状态值
                    /**
                     * bus_accounting_task submit_status: 1=未提交，2=待审核，3=审核通过，100=审核不通过
                     */
                    order.setSubmitStatus(100);
                    getDataDao.updateBusBudgetAccountingTaskByPrimaryKeySelective(order);
                } else {
                    //2.2·找到上一个节点，生成下一个节点、审批人//
                    /**
                     * 根据我当前审批记录，找到我上一个临近的、
                     */
                    AuditProcessModel addAppInfo = getDataDao.findNextUserByNgInfo(param.getId());
                    addAppInfo.setAppStatus(1);
                    getDataDao.insertVerifyProcess(addAppInfo);
                    logService.saveLog("核算清单审核", ShiroUtils.getUser().getName() + "驳回了" + order.getFounder() + "创建的项目号为" + order.getProCode() + "的核算清单！");
                }
            }
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("审核成功！");
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error(ex.getLocalizedMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("审核失败！");
        }
        return jsonResult;
    }

    /**
     * 递归：直到找到审批级别的上级人员id为止
     *
     * @param post
     * @param pid
     * @return
     */
    private int getPid(int post, int pid) {
        int userId = 0;
        AuditProcessModel nextModel = getDataDao.findNextLevelUserByPId(pid);
        if (nextModel != null) {
            if (nextModel.getPost() == post) {
                userId = nextModel.getSubmitUser();
            } else {
                getPid(post, nextModel.getParentId());
            }
        }
        return userId;
    }

    /**
     * revoke 撤销创建成本清单
     *
     * @param batId
     * @return com.zhongwang.business.common.JsonResult
     * @throws
     * @author 徐一贺
     * @date 2020/11/30 13:56
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult revoke(Integer batId) {
        JsonResult result = new JsonResult();
        try {
            Integer busMaterialDataCount = getDataDao.getBusMaterialDataCountByBatId(batId);
            Integer busMachininghoursCount = getDataDao.getBusMachininghoursCountByBatId(batId);
            Integer busGeneralHoursCount = getDataDao.getBusGeneralHoursCountByBatId(batId);
            //验证数据源获取的数据是否存在
            if (busMaterialDataCount > 0 || busMachininghoursCount > 0 || busGeneralHoursCount > 0) {
                result.setType(JsonResult.ResultType.ERROR);
                result.setMsg("撤销创建成本清单失败，因此成本清单已获取数据！");
                return result;
            } else {

                //清空任务信息
                Task task = getDataDao.getTaskByBatId(batId);
                //获取单据信息
                BusBudgetAccountingTask busBudgetAccountingTask = getDataDao.getBusBudgetAccountingTaskByPrimaryKey(batId);
                //获取项目信息
                VwProject vwProject = getDataDao.getVwProjectByCode(busBudgetAccountingTask.getProCode());
                task.setTstatus(1);
                task.setBegindate(null);
                task.setEnddate(null);
                task.setKeyperson(null);
                task.setKeypersonid(null);
                getDataDao.updateTaskInfoByPrimaryKey(task);
                //删除数据源
                getDataDao.deleteBusBudgetDataSourceByBatId(batId);
                //删除核算清单相关数据
                getDataDao.deleteBusBudgetAccountingEstimatesDataByBatId(batId);
                //删除核算清单配置数据
                getDataDao.deleteBusBudgetAccountingBasicInfoConfigByBatId(batId);
                //删除核算清单表数据
                getDataDao.deleteBusBudgetAccountingCostByBatId(batId);
                //删除单据表信息
                getDataDao.deleteBusBudgetAccountTaskByBatId(batId);
                result.setType(JsonResult.ResultType.SUCCESS);
                result.setMsg("撤销创建成本清单成功！");
                logService.saveLog("撤销创建成本清单", "撤销创建项目号为：【" + vwProject.getCode() + "】,项目名称为：【" + vwProject.getName() + "】的核算成本清单。");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error(ex.getMessage());
            result.setType(JsonResult.ResultType.ERROR);
            result.setMsg("撤销创建成本清单失败！");
        }
        return result;
    }

    /**
     * getNewUserList revoke 根据组的ID获取对应组的成员列表，切不包含当前创建人
     *
     * @param groupId  组ID
     * @param userName 当前用户
     * @return java.util.List<com.zhongwang.business.gen.entity.User>
     * @throws
     * @author 徐一贺
     * @date 2020/11/30 16:00
     */
    public List<User> getNewUserList(Integer groupId, String userName) {
        return getDataDao.findUserByDeptIdByNotUserName(groupId, userName);
    }

    /**
     * changeFounder 更换创建人
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @throws
     * @author 徐一贺
     * @date 2020/11/30 16:16
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult changeFounder(BusBudgetAccountingTaskModel param) {
        JsonResult result = new JsonResult();
        try {
            //获取单据信息
            BusBudgetAccountingTask busBudgetAccountingTask = getDataDao.getBusBudgetAccountingTaskByPrimaryKey(param.getId());
            //获取项目信息
            VwProject vwProject = getDataDao.getVwProjectByCode(busBudgetAccountingTask.getProCode());
            User beforeUser = getDataDao.getUserById(busBudgetAccountingTask.getTaskUid());
            getDataDao.updateBusBudgetAccountingTaskByPrimaryKeySelective(param);
            User afterUser = getDataDao.getUserById(param.getTaskUid());
            Task task = new Task();
            task.setId(busBudgetAccountingTask.getTaskId());
            task.setKeyperson(afterUser.getName());
            task.setKeypersonid(afterUser.getId());
            getDataDao.updateTaskInfoByPrimaryKey(task);
            result.setType(JsonResult.ResultType.SUCCESS);
            result.setMsg("更换创建入成功！");
            logService.saveLog("{id:" + param.getId() + "} 更换创建人", "更换项目号为：【" + vwProject.getCode() + "】,项目名称为：【" + vwProject.getName() + "】核算任务的创建人，更换前的创建人是】【" + beforeUser.getName() + "】更换后的创建人是【" + afterUser.getName() + "】。");
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error(ex.getMessage());
            result.setType(JsonResult.ResultType.ERROR);
            result.setMsg("更换创建入失败！");
        }
        return result;
    }

    /**
     * restTask 重置并撤销任务
     *
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @throws
     * @author 徐一贺
     * @date 2020/12/10 14:19
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult restTask(BusBudgetAccountingTaskModel param) {
        JsonResult result = new JsonResult();
        try {
            BusBudgetAccountingTask busBudgetAccountingTask = getDataDao.getBusBudgetAccountingTaskByPrimaryKey(param.getId());
            //删除审核数据
            getDataDao.deleteVerifyProcess(busBudgetAccountingTask.getId());
            getDataDao.deleteSheetDetail(busBudgetAccountingTask.getId());
            //删除获取和导入的数据
            //材料
            getDataDao.deleteBusMaterialDataByBatId(busBudgetAccountingTask.getId());
            //工时
            getDataDao.deleteBusGeneralHoursByBatId(busBudgetAccountingTask.getId());
            getDataDao.deleteBusMachiningHoursByBatId(busBudgetAccountingTask.getId());
            //删除基础数据
            getDataDao.deleteBusBudgetAccountingBasicInfoConfigByBatId(busBudgetAccountingTask.getId());
            getDataDao.deleteBusBudgetAccountingEstimatesDataByBatId(busBudgetAccountingTask.getId());
            getDataDao.deleteBusDataSourceByBatId(busBudgetAccountingTask.getId());
            //删除清单数据
            getDataDao.deleteBusBudgetAccountingCostByBatId(busBudgetAccountingTask.getId());
            //删除单据表数据
            getDataDao.deleteBusBudgetAccountingTaskByPrimaryKey(busBudgetAccountingTask.getId());
            //清空任务信息
            getDataDao.clearTaskInfo(busBudgetAccountingTask.getTaskId());
            result.setType(JsonResult.ResultType.SUCCESS);
            result.setMsg("重置成功！");
            logService.saveLog("重置并清空核算数据", "项目号:【" + busBudgetAccountingTask.getProCode() + "】");
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error(ex.getMessage());
            result.setType(JsonResult.ResultType.ERROR);
            result.setMsg("重置失败！");
        }
        return result;
    }

    /**
     * getConContractMainModelByCode 根据项目号获取合同信息
     *
     * @param proCode 项目号
     * @return com.zhongwang.business.module.contractManage.model.ConContractMainModel
     * @author 徐一贺
     * @date 2020/12/17 20:39
     */
    public ConContractMainModel getConContractMainModelByCode(String proCode) {
        return getDataDao.getConContractMainModelByCode(proCode);
    }


//    /**
//     *  getMacColumns
//     *  获取动态所需的数据列
//     * @param [batId, dsId]
//     * @return java.util.List<com.zhongwang.business.gen.entity.BusMachiningEquipment>
//     * @author 徐一贺
//     * @date 2020/10/24 11:28
//     * @version 1.0
//     */
//    public List <BusMachiningEquipment> getMacColumns(BusMachiningHoursModel param){
//        //获取该条件下所有机加设备型号
//        List <BusMachiningEquipment> columnList = getDataDao.findBusMachiningEquipmentCodeBycondition(param);
//        List <BusMachiningEquipment> newColumnList = new ArrayList<>();
//        for (BusMachiningEquipment model:columnList) {
//            if(model!=null){
//                newColumnList.add(model);
//            }
//        }
//        return newColumnList;
//    }
}
